我试着做一个非常简单的计算器。到目前为止,这就是我所拥有的,但我得到的答案真的很模糊。就像,将 2 和 2 相乘,我得到 1550532996。感谢所有帮助。
#include <iostream>
using namespace std;
int main()
{
int x;
int b;
int k;
int sum=x+b;
int difference=x-b;
int product=x*b;
int quotient=x/b;
cout<<"Enter a number"<<endl;
cin>>x;
cout<<"Enter another number."<<endl;
cin>>b;
cout<<"What do you want to do with these numbers? Enter 1 for addition, 2 for subtraction, 3 for multiplication, and 4 for division"<<endl;
cin>>k;
switch (k){
case 1:
cout<<sum<<endl;
break;
case 2:
cout<<difference<<endl;
break;
case 3:
cout<<product<<endl;
break;
case 4:
cout<<quotient<<endl;
break;
}
}