LiaFi1eNg 2017-11-30 16:19 采纳率: 0%
浏览 832

谁帮我改下怎样才能整除?

图片说明#include
#include
#include
#include
using namespace std;
int main()
{

srand((unsigned)time(NULL));
int a,b,i,c,sum,s,k;

int r=0;
cout<<"计算题"< cout cin>>k;
if(k==1)
{
ofstream f1("e:\错题.txt");

if(!f1) return 0;
for(i=0;i<=10;i++)

{
a=rand()%100;
b=rand()%100;
c=rand()%4;
if(c==1)
{
cout< cin>>s;
sum=a+b;
if(sum==s)
{
r++;
cout<<"正确"<<endl;

        }
        else
        {

        cout<<"错误"<<endl; 
        f1<<a<<"+"<<b<<"="<<endl;
    }
    }
    else if(c==2)
    {
        cout<<a<<"*"<<b<<"=";
        cin>>s;
        sum=a*b;
        if(sum==s)
        {
            r++;
            cout<<"正确"<<endl;

        }
        else
        {

        cout<<"错误"<<endl; 
        f1<<a<<"*"<<b<<"="<<endl;
    }
     } 
     else if(c==3)
     {
      cout<<a<<"÷"<<b<<"=";
      cin>>s;
      sum==a/b;
      if(sum==s)
      {
         r++; 
      cout<<"正确"<<endl;

      }
      else
      {

        cout<<"错误"<<endl;
        f1<<a<<"/"<<b<<"="<<endl;
        }
     }
        else if(c==4)
     {
      cout<<a<<"-"<<b<<"=";
      cin>>s;
      sum==a-b;
      if(sum==s)
      {
         r++; 
      cout<<"正确"<<endl;

      }
      else
      {

        cout<<"错误"<<endl;
        f1<<a<<"-"<<b<<"="<<endl;
        }
     }

}
cout<<"一共有"< cout cin>>k;

f1.close();
}
if(k==2)
{
string str;
int s;
ifstream f1("E:\错题.txt");
if(!f1) return 0;
while(getline(f1, str))
{
cout< cin>>s;
}

}

}

就是除法的时候是 20/4 15/3 35/7这种的。我自己改 每次都是什么49/89 41/24的。 求帮忙改下

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-11-30 16:24
    关注
     else if(c==3)
         {
          cout<<a<<"÷"<<b<<"=";
          cin>>s;
          sum==a/b;
    修改为
    else if(c==3)
         {
    a  = (a / b) * b;
          cout<<a<<"÷"<<b<<"=";
          cin>>s;
          sum==a/b;
    
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么在stm32门禁成品上增加记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 解riccati方程组