+ 1
Hello everyone? can u guys show me a example on how to write a menu based program on operations(+,-) using switch with functions
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;
}
+ 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
+ 8
Sure bro, whatever you need, just contact me.
+ 7
With GUI or?
+ 7
Want me to make an example program? You have my calculator with menu, if you want to check it out.
+ 7
In my codes
+ 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?
+ 7
I will make it now, okay?
+ 6
When you run a program a menu shows up, and then you have options on what operation you want to do?
+ 1
Fillip sir thanks a lot u just solved my problem
+ 1
Thnks but can u tell me the use of namespace std and its importance?I dont know as i m newbie in programming
+ 1
Thank u sir and hope u will solve my further problem always! đ
0
actually sir i meant a calculator type program where for option a (if i take addition) and function addition will show up
0
yes exactly i meant that only,the main problem is i cant execute it by using switch