我是C ++的新手,我得到了一项任务,将 b-c d转换为c ++表达式 这是我的代码行
#include<iostream>
#include<conio.h>
#include<stdio.h>
using namespace std;
int main ()
{
int a,b,c,d,e,f ,sum;
cout<<"enter value of A";
cin>>a;
cout<<"enter value of b";
cin>>b;
cout<<"Your Answer is";
cin>>a*b=e;
cout<<"enter value of c";
cin>>a;
cout<<"enter value of d";
cin>>b;
cout<<"Your Answer is";
cin>>c*d=f;
cin>>e-f;
sum=e-f;
getch();
}
您的帮助将不胜感激。
此致
答案 0 :(得分:0)
#include<iostream>
#include<conio.h>
#include<stdio.h>
using namespace std;
int main ()
{
int a,b,c,d,e,f ,sum;
cout<<"enter value of A";
cin>>a;
cout<<"enter value of b";
cin>>b;
e=a*b;
cout<<"Your Answer is"<<e<<endl;
cout<<"enter value of c";
cin>>a;
cout<<"enter value of d";
cin>>b;
f=c*d;
cout<<"Your Answer is"<<f<<end;
sum=e-f;
getch();
}
你使用cin语句来获取用户的输入,评估不是在cin语句中完成的,如果它适合你,请考虑这段代码。
答案 1 :(得分:0)
我已经修复了你想要做的一些事情,假设你使用e和f作为临时变量来计算ab-cd,并将sum作为最终变量。
#include<iostream>
#include<conio.h>
#include<stdio.h>
using namespace std;
int main ()
{
int a,b,c,d,e,f ,sum;
cout<<"enter value of A";
cin>>a;
cout<<"enter value of b";
cin>>b;
cout<<"Your Answer is";
e = a*b;
cout<<"enter value of c";
cin>>c;
cout<<"enter value of d";
cin>>d;
cout<<"Your Answer is";
f = c*d;
sum=e-f;
cout << sum;
}