#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x;
float ApplePrice = 3.5;
float BananaPrice = 4.2;
float Total = 0.0;
float AppleWeight = 0.0;
float BananaWeight = 0.0;
cout << "请输入苹果的重量" << endl;
cin >> AppleWeight;
cout << "请输入香蕉的重量" << endl;
cin >> BananaWeight;
Total = ApplePrice*AppleWeight + BananaPrice*BananaWeight;
cout << "应付款" << Total << endl;
cout << "press 1 to continue" << endl;
cin >> x;
if (x=1)
{
main();
}
else
{
system("pause");
return 0;
}
}
以上是我的代码 ,大一狗,初学者。我想让程序最后输入1重复运行 否则退出 为什么现在不管输入什么都是重复运行?求解
#include<cstdlib>
using namespace std;
int main()
{
int x;
float ApplePrice = 3.5;
float BananaPrice = 4.2;
float Total = 0.0;
float AppleWeight = 0.0;
float BananaWeight = 0.0;
cout << "请输入苹果的重量" << endl;
cin >> AppleWeight;
cout << "请输入香蕉的重量" << endl;
cin >> BananaWeight;
Total = ApplePrice*AppleWeight + BananaPrice*BananaWeight;
cout << "应付款" << Total << endl;
cout << "press 1 to continue" << endl;
cin >> x;
if (x=1)
{
main();
}
else
{
system("pause");
return 0;
}
}
以上是我的代码 ,大一狗,初学者。我想让程序最后输入1重复运行 否则退出 为什么现在不管输入什么都是重复运行?求解