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;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算