My first C++ program need help please
I want the user to choose 5 options like you can see in the switch below in my code, but I have 39 errors and I can not see one of them!
Well i post the code here, i will continue to work on it but if you can show me my error that will give me a lot for my knowledge.
Thx You in advance!!!!!!!!
Code:
#include <iostream.h>
#include <conio.h>
int x;
int y;
int addit(int x, int y);
int soust(int x, int y);
int multi(int x, int y);
int divide(int x, int y);
int exit(int x, int y);
int main()
{
int input;
cout<<"1. "Add function"<<endl;
cout<<"2. "Soustract function"<<endl;
cout<<"3. "Multi function"<<endl;
cout<<"4. "Divide function"<<endl;
cout<<"5. "Exit"<<endl;
cin>>input;
cout<<"First number"<<endl;
cin>>x;
cout<<"Second number"<<endl;
cin>>y;
switch (input)
{
case 1: addit();
addit(x,y);
cout<<addit(x,y);
break;
case 2: soust();
soust(x,y);
cout<<soust(x,y);
break;
case 3: multi();
mutli(x,y);
break;
case 4: divide();
divide(x,y);
cout<<divide(x,y);
break;
case 5: Exit();
return 0;
break;
default:
cout<<"Error, bad input, quitting");
}
return 0;
}
int addit(int x,int y)
{
return x+y;
}
int soust(int x,int y)
{
return x-y;
}
int multi(int x,int y)
{
return x*y;
}
int divide(int x,int y)
{
return x/y;
}
Re: My first C++ program need help please
You don't have to call the functions.
will be enough. You are also getting errors because you are calling the functions with no parameters. You need addit(x,y);, you can't have just addit(). Also, you put mutli instead of multi in case 3.
Get rid of the parentheses after the cout in the default case, too.
In case 5, you have exit() but your function is defined as Exit(). Remember that C++ is case-sensitive.
You don't need the break; in case 5 because the program will be done already.
Why do you have conio.h included? As far as I can see, you don't need it.
Be careful, since divide() returns an int if you do divide(3,4) you will get 0, not 0.75, because it drops off the zero.