+ 1

Hello everyone? can u guys show me a example on how to write a menu based program on operations(+,-) using switch with functions

11th Jan 2017, 2:41 PM
soop
soop - avatar
14 Answers
+ 8
#include <iostream> using namespace std; void menu() { cout<<" Menu\n\n"; cout<<" Pick the operation: \n"; cout<<"..........................\n"; cout<<"| 1) + |\n"; cout<<"| 2) - |\n"; cout<<"..........................\n\n\n"; } void addition() { int x, y; cin>>x>>y; cout<<x<<"+"<<y<<"="<<x+y; } void subtraction() { int x, y; cin>>x>>y; cout<<x<<"-"<<y<<"="<<x-y; } int main() { unsigned choice; menu(); cin>>choice; switch(choice) { case(1): addition(); break; case(2): subtraction(); break; default: cout<<"Wrong choice!"; } return 0; }
11th Jan 2017, 6:55 PM
Filip
Filip - avatar
+ 8
You know about cin and cout, main objects for input and output, with cin you get the input, and with cout you print the output, those two objects are the objects of namespace std, that's why you put 'using namespace std;'. If you don't you will then need to write cin like 'std::cin' because it is from std(standard) namespace, and others like string or vector... Hope you understand
11th Jan 2017, 7:03 PM
Filip
Filip - avatar
+ 8
Sure bro, whatever you need, just contact me.
11th Jan 2017, 7:07 PM
Filip
Filip - avatar
+ 7
With GUI or?
11th Jan 2017, 4:01 PM
Filip
Filip - avatar
+ 7
Want me to make an example program? You have my calculator with menu, if you want to check it out.
11th Jan 2017, 6:29 PM
Filip
Filip - avatar
+ 7
In my codes
11th Jan 2017, 6:31 PM
Filip
Filip - avatar
+ 7
I don't know if you mean menu like that one, or menu where you can choose the operation and then get the inputs?
11th Jan 2017, 6:32 PM
Filip
Filip - avatar
+ 7
I will make it now, okay?
11th Jan 2017, 6:40 PM
Filip
Filip - avatar
+ 6
When you run a program a menu shows up, and then you have options on what operation you want to do?
11th Jan 2017, 6:36 PM
Filip
Filip - avatar
+ 1
Fillip sir thanks a lot u just solved my problem
11th Jan 2017, 6:46 PM
soop
soop - avatar
+ 1
Thnks but can u tell me the use of namespace std and its importance?I dont know as i m newbie in programming
11th Jan 2017, 6:57 PM
soop
soop - avatar
+ 1
Thank u sir and hope u will solve my further problem always! 😀
11th Jan 2017, 7:07 PM
soop
soop - avatar
0
actually sir i meant a calculator type program where for option a (if i take addition) and function addition will show up
11th Jan 2017, 6:35 PM
soop
soop - avatar
0
yes exactly i meant that only,the main problem is i cant execute it by using switch
11th Jan 2017, 6:39 PM
soop
soop - avatar