| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 245 人关注过本帖
标题:这个程序有点问题 谁能帮忙改一下
取消只看楼主 加入收藏
miya829475
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-3-8
结帖率:100%
收藏
已结贴  问题点数:6 回复次数:0 
这个程序有点问题 谁能帮忙改一下
运行时输入2或三会出现负数
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int FAQ (int num,int scrone);
int main (void)
{
    int num;//题数
    int  cou,s=0,scrone;//得数,分数 ,单题分数
     
    //主界面
    printf ("***********欢迎使用 小学算术运算测试 程序**************\n");
    printf ("程序说明:\n");
    printf ("        用户输入要回答的题数后,系统将会随机产生相应数目的\n");
    printf ("        题目用户依次回答题目,系统将根据回答的正确与否给分\n");     
    printf ("请输入要回答的题数:");
    scanf ("%d",&num);
    scrone=100/num;
    s=FAQ(num,scrone);
   
    printf ("您回答了%d道题,满分为100分,您得到了%d分\n",num,s*100/num)  ;
    printf ("请输入回车键退出程序");
    getchar();
    getchar();
}     
int FAQ(int num,int scrone)//问答模块
{
   
    int ope,n1,n2,ans; //运算符,数1,数2,答案
    int cou,scr=0;//得数,分数
    int i,j;//循环用控制数
    time_t t;
    srand((unsigned) time(&t));
    for (i=0;i<num;i++)
    {
        ope=rand()%4;
        switch (ope)
        {
               case 0: {
                         n1=rand()%100;
                         n2=rand()%100;
                         ans=n1+n2;
                         printf ("%d+%d=",n1,n2);
                         scanf ("%d",&cou);
                         printf("正确答案为:%d\n",ans);
                         if (ans==cou)
                         scr=scr+1;
                         continue;
                         }
               case 1: {
                         while (n1<n2)
                         {
                         n1=rand()%100;
                         n2=rand()%100;
                         }
                         ans=n1-n2;
                         printf ("%d-%d=",n1,n2);
                         scanf ("%d",&cou);
                         printf("正确答案为:%d\n",ans);
                          if (ans==cou)
                         scr=scr+1;
                         continue;
                         }
                case 2: {
                         n1=rand()%100;
                         n2=rand()%100;
                         ans=n1*n2;
                         printf ("%d*%d=",n1,n2);
                         scanf ("%d",&cou);
                         printf("正确答案为:%d\n",ans);
                          if (ans==cou)
                         scr=scr+1;
                         continue;
                         }
                 case 3: {
                         while (n2!=0&&n1>n2)
                         {
                         n1=rand()%100;
                         n2=rand()%100;
                         }
                         ans=n1/n2;
                         printf ("%d/%d=",n1,n2);
                         scanf ("%d",&cou);
                         printf("正确答案为:%d\n",ans);
                          if (ans==cou)
                         scr=scr+1;
                         continue;
                         }
                         }
                        
                         }
                         return (scr);
                         }
搜索更多相关主题的帖子: include 用户 
2011-03-09 08:45
快速回复:这个程序有点问题 谁能帮忙改一下
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.039858 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved