// Calculator.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <cstdlib>
using namespace std;

int  GetNumber1();
void GetMathematicalOperation();
int  GetNumber2();
int CalculateResult();
int PrintResult();

int main()
{
	GetNumber1();
	GetMathematicalOperation();
	GetNumber2();
	CalculateResult();
	PrintResult();
     
	int CalculateResult( int x, char chOperation, int y);
	int PrintResult( CalculateResult( int x, char chOperation, int y));
}

int GetNumber1()
{
	cout << "Enter first number: ";
	int x;
	cin >> x;
	return x;
}

char GetMathematicalOperation();
{
	cout << "Enter operator: ";
	char chOperation;
	cin >> chOperation;
	return chOperation;
}

int GetNumber2();
{
	cout << "Enter second number: ";
	int y;
	cin >> y;
	return y;
}

ERROR in compiler:

1>------ Build started: Project: Calculator, Configuration: Debug Win32 ------
1>Compiling...
1>Calculator.cpp
1>d:\c++projects\calculator\calculator\calculator.cpp(23) : error C2144: syntax error : 'int' should be preceded by ')'
1>d:\c++projects\calculator\calculator\calculator.cpp(23) : error C2660: 'CalculateResult' : function does not take 0 arguments
1>d:\c++projects\calculator\calculator\calculator.cpp(23) : error C2059: syntax error : ')'
1>d:\c++projects\calculator\calculator\calculator.cpp(34) : error C2556: 'char GetMathematicalOperation(void)' : overloaded function differs only by return type from 'void GetMathematicalOperation(void)'
1>        d:\c++projects\calculator\calculator\calculator.cpp(9) : see declaration of 'GetMathematicalOperation'
1>d:\c++projects\calculator\calculator\calculator.cpp(34) : error C2371: 'GetMathematicalOperation' : redefinition; different basic types
1>        d:\c++projects\calculator\calculator\calculator.cpp(9) : see declaration of 'GetMathematicalOperation'
1>d:\c++projects\calculator\calculator\calculator.cpp(35) : error C2447: '{' : missing function header (old-style formal list?)
1>d:\c++projects\calculator\calculator\calculator.cpp(43) : error C2447: '{' : missing function header (old-style formal list?)
1>Build log was saved at "file://d:\c++projects\Calculator\Calculator\Debug\BuildLog.htm"
1>Calculator - 7 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Thanks!

Lines 22 and 23 are prototypes which should in 99.9% of cases be placed outside of main replacing lines 11 and 12. GetNumber1() and GetNumber2() functions are returning values and you're not "catching" them with anything like a variable local to main().I understand what you were assuming but the x and y within those functions is out of scope so they can't be seen in main().

Look up some examples in your text as to how functions are called in main(). They don't need the return type and you don't need the type on the parameters either.

Edited 6 Years Ago by jonsca: n/a

Still need help:

// Calculator.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <cstdlib>
using namespace std;

int  GetNumber1();
void GetMathematicalOperation();
int  GetNumber2();
int CalculateResult( int x, char chOperation, int y);
int PrintResult( CalculateResult( int x, char chOperation, int y));

int main()
{
	GetNumber1();
	GetMathematicalOperation();
	GetNumber2();
	CalculateResult();
	PrintResult();
}

int GetNumber1()
{
	cout << "Enter first number: ";
	int x;
	cin >> x;
	return x;
}

char GetMathematicalOperation();
{
	cout << "Enter operator: ";
	char chOperation;
	cin >> chOperation;
	return chOperation;
}

int GetNumber2();
{
	cout << "Enter second number: ";
	int y;
	cin >> y;
	return y;
}
1>------ Build started: Project: Calculator, Configuration: Debug Win32 ------
1>Compiling...
1>Calculator.cpp
1>d:\c++projects\calculator\calculator\calculator.cpp(12) : error C2144: syntax error : 'int' should be preceded by ')'
1>d:\c++projects\calculator\calculator\calculator.cpp(12) : error C2660: 'CalculateResult' : function does not take 0 arguments
1>d:\c++projects\calculator\calculator\calculator.cpp(12) : error C2059: syntax error : ')'
1>d:\c++projects\calculator\calculator\calculator.cpp(19) : error C2660: 'CalculateResult' : function does not take 0 arguments
1>d:\c++projects\calculator\calculator\calculator.cpp(20) : error C3861: 'PrintResult': identifier not found
1>d:\c++projects\calculator\calculator\calculator.cpp(31) : error C2556: 'char GetMathematicalOperation(void)' : overloaded function differs only by return type from 'void GetMathematicalOperation(void)'
1>        d:\c++projects\calculator\calculator\calculator.cpp(9) : see declaration of 'GetMathematicalOperation'
1>d:\c++projects\calculator\calculator\calculator.cpp(31) : error C2371: 'GetMathematicalOperation' : redefinition; different basic types
1>        d:\c++projects\calculator\calculator\calculator.cpp(9) : see declaration of 'GetMathematicalOperation'
1>d:\c++projects\calculator\calculator\calculator.cpp(32) : error C2447: '{' : missing function header (old-style formal list?)
1>d:\c++projects\calculator\calculator\calculator.cpp(40) : error C2447: '{' : missing function header (old-style formal list?)
1>Build log was saved at "file://d:\c++projects\Calculator\Calculator\Debug\BuildLog.htm"
1>Calculator - 9 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Yes, but I'm not going to be a compiler interpreter for you. Read the other things I told you. You need to have 2 integer values to return GetNumber1() and GetNumber2() into. So declare 2 ints. You'll need another one for CalculateResults. I don't see your PrintResult function anywhere so you need to implement it. You have it returning a value but you may not need one.

Ill go ask in another forum, because I started yesterday and I want to know whats wrong, not that you should explain the basics. TY

I was willing to help you. I'm not going to simply give you the answer because you'll have to keep coming back and having me iterate through your compiler errors every time something comes up. I was just saying look over some example programs in your text (or a text) because you're missing some fundamental points.

Ill go ask in another forum, because I started yesterday and I want to know whats wrong, not that you should explain the basics. TY

You really need to take a look into the basics, one basic -> C++ Tutorial.
Perhaps start at Chapter 1, if you are interested in that tutorial.

This article has been dead for over six months. Start a new discussion instead.