【发布时间】:2023-03-20 08:39:02
【问题描述】:
当我们将这封信插入控制台时,它开始在第 19 行和第 42 行重复。当我通常写发票时,它对我有用。
请帮助解决这个问题。
#include<iostream>
using namespace std;
int main()
{
float num1, num2;
char operator1;
bool repeat = true;
while (repeat)
{
char odgovor; //odgovor da ali ne v katerega bom spravil v bool(true / false)
cout << "do you want to continue d(yes) or n(no) " << endl;
cin >> odgovor;
repeat = odgovor == 'd';
cout << "enter the calculation" << endl;
cin >> num1 >> operator1 >> num2; //vnos dveh števil in operatorja
switch (operator1)
{
case'-':cout << num1 << " " << operator1 << " " << num2 << " = " << num1 - num2 << endl; break;
case'+':cout << num1 << " " << operator1 << " " << num2 << " = " << num1 + num2 << endl; break;
case'/':cout << num1 << " " << operator1 << " " << num2 << " = " << num1 / num2 << endl; break;
case'*':cout << num1 << " " << operator1 << " " << num2 << " = " << num1 * num2 << endl; break;
case'%':
bool isNum1Int, isNum2Int;
isNum1Int = ((int)num1 == num1);
isNum2Int = ((int)num2 == num2);
if (isNum1Int && isNum2Int)
{
cout << (int)num1 << " " << operator1 << " " << (int)num2 << " = " << (int)num1 %(int)num2 << endl; break;
}
else {
cout << "the number must be an integer" << endl; break;
}
default:cout << "not valid" << endl; break;
}
}
return 0;
}
【问题讨论】:
-
请为您的帖子选择一个标题,以帮助其他有同样问题的人。
标签: c++ math calculator