Need better understanding + need to solve an error.

I'm learning C++ off of this very website, and i'm up to this section : http://www.learncpp.com/cpp-tutorial/1-10a-how-to-design-your-first-programs/
im trying to create a very simple calculator and just need 2 things from you guys:
1. As you have "int main" there is "char operation" what is char? character?, and if so, then what characters is it for?
2. What is meant by the error and how do i fix it? "error C2660: 'Calculate' : function does not take 0 arguments"

Here is a copy of my code, and i'm using Microsoft Visual Studio Express 2013 for Windows Desktop. I will reply to any questions ASAP. Thanks

1 #include "stdafx.h"
2 #include <iostream>
3
4 int Getuserinput()
5 {
6 using namespace std;
7 cout << "Get user input: ";
8 int userinput;
9 cin >> userinput;
10 return userinput;
11 }
12
13 char Getuseroperation()
14 {
15 using namespace std;
16 cout << "Please enter a function (+,-,*,/) : ";
17 char operation;
18 cin >> operation;
19 return 0;
20 }
21
22 int Getuserinput2()
23 {
24 using namespace std;
25 cout << "Enter second digit : ";
26 int userinput2;
27 cin >> userinput2;
28 return 0;
29 }
30
31 int Calculate(int userinput,char operation,int userinput2)
32 {
33 if (operation == '+')
34 return userinput + userinput2;
35 if (operation == '-')
36 return userinput - userinput2;
37 if (operation == '/')
38 return userinput / userinput2;
39 if (operation == '*')
40 return userinput * userinput2;
41 return 0;
42 }
43 int main()
44 {
45 //User enetered number
46 Getuserinput();
47 Getuseroperation();
48 Getuserinput2();
49 Calculate();
50 }
char is a built-in data type. It holds one character.
http://www.cplusplus.com/doc/tutorial/variables/


"error C2660: 'Calculate' : function does not take 0 arguments"
31 int Calculate(int userinput,char operation,int userinput2)
49 Calculate();

You've defined Calculate to take 3 arguments, an int, char and an int. But when you call the function on line 49, you don't send those.

turns out i knew what char was, i just forgot, and how do i send them? i have no idea.
You aren't assigning the results of Getuserinput(), Getuseroperation(), and Getuserinput2() to anything. You can fix it like this:

In main():
1
2
3
4
5
6
7
int userInput1 = Getuserinput();
char userOperation = Getuseroperation();
int userInput2 = Getuserinput2();

int result = Calculate(userInput1, userOperation, userInput2);

cout << result;


You also only need to put using namespace std; once under your includes.

Edit:

In Getuseroperation() and Getuserinput2() you are returning 0 instead of operation and userInput2.
Last edited on
Thanks, got it working perfect now =D
Topic archived. No new replies allowed.