Click to See Complete Forum and Search --> : Newbie C++ help


l2oBiN_Ho0D
September 18th, 2002, 07:03 AM
Hi guys, ive been asked to create a simple calculator in c++ and this is what i came up with using microsoft visual c++


//Solution Algorythmns
#include <iostream.h>

int main
;SetCounters();ProcessNumbers();DisplayOutput(){

//start of "SetCounters" module.
int SetCounters();
int MoreNumbers;
MoreNumbers = 0;
int TotalCounter;
TotalCounter = 0;
// end of "SetCounters" module.


//start of "Input" module.
int Input();
int Number1;
int Action;
int Number2;
cout<<"Please insert your first number";
cin>>Number1;
cout<<"please insert what you want to do, +,-,* or /";
cin>>Action;
cout<<"please insert your second number";
cin>>Number2;
//end of "Input" module


//start of "ProcessNumbers" module.
int ProcessNumbers();
while (MoreNumbers==0){
Input();
cout<<"The calculation is"<<Number1+Action+Number2<<"\n";
TotalCounter = Number1+Action+Number2;
cout<<"are there more numbers to be calculated? Y=0, N=1";
cin>>MoreNumbers;
}
//end of "ProcessNumbers" module.
int DisplayOutput();
cout<<TotalCounter;
//end of "ProcessNumbers" module
return 0;
}


when i compiled it said everything is ok (no errors or warnings), but when i clicked build i got 3 errors, i got no idea where i stuffed up..
The errors are:

Linking...
Try.obj : error LNK2001: unresolved external symbol "int __cdecl Input(void)" (?Input@@YAHXZ)
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Try.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

Can anyone see the problem?? also, i kno there must be some logic errors there as this is the first time im doing something like this,in particular the line
" TotalCounter = Number1+Action+Number2;" doesent seem right to me, does anyone know if this is right? and if its not, how can i go around this problem?
thank you to anyone who goes out of their way to help me...
:(

Federal102
September 18th, 2002, 08:37 AM
This code...
[code]
TotalCounter = Number1+Action+Number2;
[\code]

will not work.

Your "Action" variable is an int. When you try to assign a char such as "+", the assignment will fail. What you need to do is figure out what operator the user entered and then use code to convert that into a mathematical operation.

Something like...

[code]
int x = 5;
int y = 10;
int result = 0;
char operator = "+";

if(operator == "+")
{
result = x + y;
}

[\code]

stober
September 18th, 2002, 08:10 PM
Real calculators use Reverse Polish-Notation. I am not an expert on this so you should look it up on the internet. Here is one simple explanation:

http://www.calculator.org/rpn.html

l2oBiN_Ho0D
September 19th, 2002, 04:43 AM
thanx guyz, been of great help, as yous probably noticed im new, and i do appreciate the help :)