以下程序在计算选择后终止,没有进一步发生。所以我的问题是我在做什么错?请有人检查这个程序并通知我我的错误。这个程序是一个计算器,它要求用户选择计算方法,即加法,除法或乘法等,然后显示计算后的结果图片:http: //i43.tinypic.com/2hykpjp.png 恕我直言C 编程新手。
main()
{
// declaration
int add,sub,mul,div,selection;
float a,b,c;
// prompt user to select a method
cout << "Calculator, which performs addition,subtraction,multiplication and division: add,sub,mul,div";
cout << "Please enter your selection (for example: mul): ";
cin >> selection;
if (selection = add)
{
// prompt user to enter values
cout << "Please enter first value: ";
cin >> a;
cout << "Please enter second value: ";
cin >> b;
// calculations
c = a + b;
// result
cout << "Answer: " << c;
}
if (selection == sub)
{
// prompt user to enter values
cout << "Please enter first value: ";
cin >> a;
cout << "Please enter second value: ";
cin >> b;
// calculations
c = a - b;
// result
cout << "Answer: " << c;
}
if (selection == mul)
{
// prompt user to enter values
cout << "Please enter first value: ";
cin >> a;
cout << "Please enter second value: ";
cin >> b;
// calculations
c = a * b;
// result
cout << "Answer: " << c;
}
if (selection == div)
{
// prompt user to enter values
cout << "Please enter first value: ";
cin >> a;
cout << "Please enter second value: ";
cin >> b;
// calculations
c = a / b;
// result
cout << "Answer: " << c;
}
}