Hi guys, i was wondering if anyone could help me with a c++ project..
I wrote this code in dev c++ but for some reason it wouldnt compile..it says the syntax in the "switch/case" is wrong but i cant find any errors <_<
i am a newb and i just started learning c++ a few days ago..
heres my code:
#include <iostream>
using namespace std;
int input;
int main()
{
cout<<"Please make a selection from the following: \n";
cout<<"To add press 1\n";
cout<<"To multiply press 2\n";
cout<<"To subtract press 3\n";
cin>> input;
switch (input)
{
case 1:
add(int a, int b);
break;
case 2:
mult(int c, int d);
break;
case 3:
sub(int e, int f);
break;
default:
cout<<"Wrong input, Quitting.\n";
break;
}
}
int add(int a, int b)
{
cout<<"Please enter two numbers\n";
cin>> a >> b;
cout<<"The total is: " << add(a,b) <<"\n";
return a + b;
}
int mult(int c, int d)
{
cout<<"Please enter two numbers to multiply\n";
cin>> c >> d;
cout<<"The product is: " << mult (c,d) <<"\n";
return c * d;
}
int sub(int e, int f)
{
cout<<"Please enter two numbers to subtract\n";
cin>> e >> f;
cout<<"The total is: " << sub(e,f) <<"\n";
return e - f;
}
any help would be much appreciated.
thx
I wrote this code in dev c++ but for some reason it wouldnt compile..it says the syntax in the "switch/case" is wrong but i cant find any errors <_<
i am a newb and i just started learning c++ a few days ago..
heres my code:
#include <iostream>
using namespace std;
int input;
int main()
{
cout<<"Please make a selection from the following: \n";
cout<<"To add press 1\n";
cout<<"To multiply press 2\n";
cout<<"To subtract press 3\n";
cin>> input;
switch (input)
{
case 1:
add(int a, int b);
break;
case 2:
mult(int c, int d);
break;
case 3:
sub(int e, int f);
break;
default:
cout<<"Wrong input, Quitting.\n";
break;
}
}
int add(int a, int b)
{
cout<<"Please enter two numbers\n";
cin>> a >> b;
cout<<"The total is: " << add(a,b) <<"\n";
return a + b;
}
int mult(int c, int d)
{
cout<<"Please enter two numbers to multiply\n";
cin>> c >> d;
cout<<"The product is: " << mult (c,d) <<"\n";
return c * d;
}
int sub(int e, int f)
{
cout<<"Please enter two numbers to subtract\n";
cin>> e >> f;
cout<<"The total is: " << sub(e,f) <<"\n";
return e - f;
}
any help would be much appreciated.
thx
Comment