Functions problem

Hello everyone! I have received your help lately with an enumeration type of the same program but now i want to continue my calculator program and here is what i have:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <cstdlib>
using namespace std;
int addition()
{int a, b;
 cin>>a;cin>>b;
 a=a+b;
 cout<<a;
 return 0;}
int main()
{int a,b;
 cout<<"Hello friend! This program is to calculate some mathematycal operations for you."<<endl;
 cout<<"Please enter the operation you want to execute as +(for addition), -(for substitution), *(for multiplication), /(for division), ^(for power), r(for  square)"<<endl;
 enum answer_type {add='+', sub='-', mul='*', div='/', pow='^', sqrt='r', invalid='0'} answer;
 char input;
 cin>>input;
 switch(input)
 {case add: addition(a,b);answer= answer_type(input);break;
  case sub: cout<<"substitution";answer= answer_type(input);break;
  case mul: cout<<"multiplication";answer= answer_type(input);break;
  case div: cout<<"division";answer= answer_type(input);break;
  case pow: cout<<"power";answer= answer_type(input);break;
  case sqrt: cout<<"square";answer= answer_type(input);break;
  default: cout<<"Incorrect answer";answer=invalid;break;};
 cout<<endl; 
 system("PAUSE");
 return 0;
}

i get two errors on compiling this code.
5 C:\... too many arguments to function `int addition()'
18 C:\... at this point in file
I hope you can hep me figure out where is the problem.Thank you in advance
The prototype for function addition is
int addition()

As per this prototype, it should not take any input paramters. However when calling this function, you are providing it two input paramters a and b.

case add: addition(a,b);
This is incorrect.
so how should i use this ffunction in this context.. or i modify the function?

I'm sorry , i just figured it out thanks to abhishekm71.. sorry for bothering.. Thank you!
Thanks to you guys i have finished the final version of my program:D
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <iostream>
#include <cstdlib>
#include<math.h>
using namespace std;
int addition()
{long int a, b;
 cout<<"Ok then! You have chosen wisely..ADDITION!"<<endl;
 cout<<"Now please enter  your first number:";
 cin>>a;
 cout<<endl;
 cout<<"Excellent choice! What about the second? It is:";
 cin>>b;
 cout<<endl;
 a=a+b;
 cout<<"Hm.. Let me think! Your result sholud be.."<<a<<"!"<<endl;
 return 0;}
int substraction()
{long int a, b;
 cout<<"Ok then! You have chosen wisely..SUBSTRACTION!"<<endl;
 cout<<"Now please enter  your first number:";
 cin>>a;
 cout<<endl;
 cout<<"Excellent choice! What about the second? It is:";
 cin>>b;
 cout<<endl;
 a=a-b;
 cout<<"Hm.. Let me think! Your result sholud be.."<<a<<"!"<<endl;
 return 0;}
int multiplication()
{long int a, b;
 cout<<"Ok then! You have chosen wisely..MULTIPLICATION!"<<endl;
 cout<<"Now please enter  your first number:";
 cin>>a;
 cout<<endl;
 cout<<"Excellent choice! What about the second? It is:";
 cin>>b;
 cout<<endl;
 a=a*b;
 cout<<"Hm.. Let me think! Your result sholud be.."<<a<<"!"<<endl;
 return 0;}
int division()
{float a, b;
 long double c;
 cout<<"Ok then! You have chosen wisely..DIVISION!"<<endl;
 cout<<"Now please enter  your first number:";
 cin>>a;
 cout<<endl;
 cout<<"Excellent choice! What about the second? It is:";
 cin>>b;
 cout<<endl;
 c=a/b;
 cout<<"Hm.. Let me think! Your result sholud be.."<<c<<"!"<<endl;
 return 0;}
int power()
{long int a, b, result=1;
 cout<<"Ok then! You have chosen wisely..POWER!"<<endl;
 cout<<"Now please enter  your base:";
 cin>>a;
 cout<<endl;
 cout<<"Excellent choice! What about the power? It is:";
 cin>>b;
 cout<<endl;
 for(; b>0; b--){result=result*a;};
 cout<<"Hm.. Let me think! Your result sholud be.."<<result<<"!"<<endl;
 return 0;}
int square()
{long double a, b;
 cout<<"Ok then! You have chosen wisely..SQUARE ROOT!"<<endl;
 cout<<"Now please enter  your number:";
 cin>>a;
 cout<<endl;
 b=sqrt(a);
 cout<<"Hm.. Let me think! Your result sholud be.."<<b<<"!"<<endl;
 return 0;}
int main()
{cout<<"Hello friend! This program is to calculate some mathematycal operations for you."<<endl;
 label1:
 cout<<"Please enter the operation you want to execute as +(for addition), -(for substraction), *(for multiplication), /(for division), ^(for power), r(for  square root)"<<endl;
 enum answer_type {add='+', sub='-', mul='*', div='/', pow='^', sqrt='r', invalid='0'} answer;
 char input, choice;
 cin>>input;
 switch(input)
 {case add: addition();answer= answer_type(input);break;
  case sub: substraction();answer= answer_type(input);break;
  case mul: multiplication();answer= answer_type(input);break;
  case div: division();answer= answer_type(input);break;
  case pow: power();answer= answer_type(input);break;
  case sqrt: square();answer= answer_type(input);break;
  default: cout<<"Incorrect answer!"<<endl;answer=invalid;break;};
 system("PAUSE");
 cout<<"Now if you want to make more operations with my program press c, if not press q."<<endl;
 label3:
 cout<<"Your choice will be:";
 cin>>choice;
 cout<<endl;
 switch(choice)
 {case 'c': goto label1; break;
  case 'q': goto label2; break;
  default: goto label3; break;};
 label2:
 return 0;
}

Thank you cplusplus.com
Topic archived. No new replies allowed.