#include <iostream>
usingnamespace std;
void sum(int num1, int num2);
void difference(int num1, int num2);
void product(int num1, int num2);
void qoutient(int num1, int num2);
int main()
{
int num1;
int num2;
cout<<"Enter your first number : ";
cin>>num1;
cout<<"Enter your second number : ";
cin>>num2;
sum(num1, num2);
difference(num1, num2);
product(num1, num2);
qoutient(num1, num2);
}
void sum(int num1, int num2)
{
cout<<"The result is : "<<num1+num2;
}
void difference(int num1, int num2)
{
cout<<"The result is : "<<num1-num2;
}
void product(int num1, int num2)
{
cout<<"The result is : "<<num1*num2;
}
void qoutient(int num1, int num2)
{
cout<<"The result is : "<<num1/num2;
}
The only thing you need to add is a new line at the end of the function calls or cout statements: cout << "The result is : " << num1+num2 << "\n";
What do you mean by stopping? Do you mean adding in a way to "Pause" the program so the user can read the sum, press a button, then read the difference, and so on?
There is a few ways to do that. You can add a system pause (this isn't a good way to do it), you can create your own style of a pause, or do a number of other things.
Do you only want it to display the sum?
Simply remove the calls to the other four functions. If you only want to display the sum, why did you create the functions for difference, product, and quotient? That seems kinda dumb.
If the switch wasn't what you wanted (it allows you to select which answer you want to see), then I'm unsure why you have four functions if you don't want all four.
BTW, OP stands for Original Poster. The comments were saying that we're not 100% as to what you're asking for. If you'd like to clarify, walk us through, step by step, what you'd like your program to do. What you want the display to look like, and what you want the user to enter. I have a fairly good idea as to what you're asking for, but still not positive.
switch isn't magic. All it does is pick something to do based on a value of a variable. It is up to you to set that variable. If you want that variable to be set by the user, you have to write some code to get input from the user.
Simply remove the calls to the other four functions. If you only want to display the sum, why did you create the functions for difference, product, and quotient? That seems kinda dumb.
Why did he create functions in the first place? There is no need to when doing something like this.
#include <iostream>
usingnamespace std;
void sum(int num1, int num2);
void difference(int num1, int num2);
void product(int num1, int num2);
void qoutient(int num1, int num2);
int main()
{
int num1;
int num2;
char op;
cout<<"Enter your first number : ";
cin >> num1 >> op >> num2;
switch(op) {
case('+'): // if op = '+'
sum(num1, num2);
break;
case('-'): // if op = '-'
difference(num1, num2);
break;
case('/'): // if op = '/'
qoutient(num1, num2);
break;
case('*'): // if op = '*'
product(num1, num2);
break;
}
return 0;
}
void sum(int num1, int num2)
{
cout<<"The result is : "<<num1+num2;
}
void difference(int num1, int num2)
{
cout<<"The result is : "<<num1-num2;
}
void product(int num1, int num2)
{
cout<<"The result is : "<<num1*num2;
}
void qoutient(int num1, int num2)
{
cout<<"The result is : "<<num1/num2;
}
@op: btw, your request is a little bit strange/weird... in case that what xhtmlx or volatile's codes is not what you wanted, then, your request is gotta be very odd... just from my personal opinion...