- 分享
- 0
- 人气
- 0
- 主题
- 23
- 帖子
- 124
- UID
- 186218
- 积分
- 122
- 阅读权限
- 13
- 注册时间
- 2008-12-16
- 最后登录
- 2012-3-17
- 在线时间
- 358 小时
|
#include <cstdlib>
#include <iostream>
using namespace std;
各位大大,我想要input 一个file进来program然后run calculator 该如何?
例子:我有一个file input.dat 里面资料有
93
50
+
70
*
然后我要让他变成(93+50)*70
那该如何呢?请给下意见谢谢!!
int main()
{
double num;
double num2;
char choice;
for (;;){
do {
cout<<"Welcome to thejoshcalculator. V1.5\n";
cout<<"Please choose an option by entering the number, press q to quit\n";
cout<<"1 - Addition\n";
cout<<"2 - Subtraction\n";
cout<<"3 - Division\n";
cout<<"4 - Multiplication\n";
cin>>choice;
} while ( choice < '1' || choice > '7' && choice != 'q');
if (choice == 'q') break;
switch (choice) {
case '1':
cout<<"Please enter a number\n";
cin>>num;
cout<<"Another number to be added\n";
cin>>num2;
cout<<num + num2;
cout<<"\n";
break;
case '2':
cout<<"Please enter a number\n";
cin>>num;
cout<<"Another number to be subtracted\n";
cin>>num2;
cout<<num - num2;
cout<<"\n";
break;
case '3':
cout<<"Please enter a number\n";
cin>>num;
cout<<"Another one to be divided\n";
cin>>num2;
cout<<num / num2;
cout<<"\n";
break;
case '4':
cout<<"Please enter a number\n";
cin>>num;
cout<<"Another one to be multiplied\n";
cin>>num2;
cout<<num * num2;
cout<<"\n";
break;
default:
cout<<"That is not an option";
}
}
return 0;
} |
|