CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Newbie C++ help

  1. #1
    Join Date
    Sep 2002
    Posts
    2

    Unhappy Newbie C++ help

    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...

  2. #2
    Join Date
    Jun 2002
    Location
    Boston, MA
    Posts
    139
    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]

  3. #3
    Join Date
    Jun 2002
    Posts
    1,417
    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

  4. #4
    Join Date
    Sep 2002
    Posts
    2
    thanx guyz, been of great help, as yous probably noticed im new, and i do appreciate the help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured