By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,118 Members | 856 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,118 IT Pros & Developers. It's quick & easy.

write a program that will mimic a calculator

P: 7
please help me....
using selection structure
the program should take as input two integers and the operation to be performed, iust as it would be entered into a standard calculator. it should output to the screen the same input, including the operator and the result of the operation. example: input2+2, and output 2+2=4
thank.
Mar 12 '07 #1
Share this Question
Share on Google+
4 Replies


sicarie
Expert Mod 2.5K+
P: 4,677
please help me....
using selection structure
the program should take as input two integers and the operation to be performed, iust as it would be entered into a standard calculator. it should output to the screen the same input, including the operator and the result of the operation. example: input2+2, and output 2+2=4
thank.
Ok, what do you need help with?
Mar 12 '07 #2

10K+
P: 13,264
please help me....
using selection structure
the program should take as input two integers and the operation to be performed, iust as it would be entered into a standard calculator. it should output to the screen the same input, including the operator and the result of the operation. example: input2+2, and output 2+2=4
thank.
You may consider using a switch. So what code have you written so far?
Mar 12 '07 #3

P: 7
You may consider using a switch. So what code have you written so far?
i only know the flowing. i don't know how to use switch.
Expand|Select|Wrap|Line Numbers
  1. int answer;
  2.     int num1=0;
  3.     int num2=0;
  4.     char ch = ' ';
  5.  
  6.     cout << "Welcome to the calculator" << endl;
  7.     cout << "Enter your equation as number operation number" << endl;
  8.     cout << "(Example: 3 + 4): ";
  9.  
  10.     cin>>num1>>ch>>num2;
  11.          cout<<num1<<ch<<num2<<"="<<num1+num2<<endl;
Mar 13 '07 #4

sicarie
Expert Mod 2.5K+
P: 4,677
i only know the flowing. i don't know how to use switch.
Expand|Select|Wrap|Line Numbers
  1. int answer;
  2.     int num1=0;
  3.     int num2=0;
  4.     char ch = ' ';
  5.  
  6.     cout << "Welcome to the calculator" << endl;
  7.     cout << "Enter your equation as number operation number" << endl;
  8.     cout << "(Example: 3 + 4): ";
  9.  
  10.     cin>>num1>>ch>>num2;
  11.          cout<<num1<<ch<<num2<<"="<<num1+num2<<endl;
Looks great so far. Did you research the switch statement as r0 suggested?
Mar 13 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.