First Project-Calculator

This is a discussion on First Project-Calculator within the C++ Programming forums, part of the General Programming Boards category; Recently I started to learn c++, although few of my files would actually compile, this is my latest atempt at ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    41

    Question First Project-Calculator

    Recently I started to learn c++, although few of my files would actually compile, this is my latest atempt at making a working C++ program. This is a simple calculator that can peform 2 operations, Multiplacation and Division. As usual, my project refuses to compile, Im using Dev C++ 4.9.9.2, and get the following errors when compiling:

    Code:
     D:\C ++\Project No.2 Calculator\MiniC.cpp In function `int main(int, char**)':
    11 D:\C ++\Project No.2 Calculator\MiniC.cpp expected primary-expression before ':' token 
    11 D:\C ++\Project No.2 Calculator\MiniC.cpp expected `;' before ':' token  
    43 D:\C ++\Project No.2 Calculator\MiniC.cpp expected `;' before string constant 
    70 D:\C ++\Project No.2 Calculator\MiniC.cpp expected `;' before string constant 
    78 D:\C ++\Project No.2 Calculator\MiniC.cpp break statement not within loop or switch 
    45 D:\C ++\Project No.2 Calculator\MiniC.cpp label `mMenu' used but not defined 
     D:\C ++\Project No.2 Calculator\Makefile.win [Build Error]  [MiniC.o] Error 1

    Heres the code:

    Code:
     //Mini calculator used for multiplication and division
    #include <cstdlib>
    #include <iostream>
    #include <cstdio>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        //ask for conversion of Multiplacation and Division
        :mMenu;
        system("cls");
        cout<<"Calculator Mini v1\n\n";
        cout<<"1. Multiplacation.\n";
        cout<<"2. Division.\n";
        cout<<"3. Exit.\n";
        int mMenuc;
        cout<<"\nYour decision (1,2,3):";
        cin>>mMenuc;
        
        //Multiplacation
        if (mMenuc==1)
        {
                      //value 1
                      float multi1;
                      system("cls");
                      cout<<"Mini Calculator v1\n\n";
                      cout<<"Please enter value 1:";
                      cin>>multi1;
                      
                      //value 2
                      float multi2;
                      system("cls");
                      cout<<"Mini Calculator v1\n\n";
                      cout<<"Please enter value 2:";
                      cin>>multi2;
                      
                      //Output
                      float multiO;
                      multiO=multi1*multi2;
                      system("cls");
                      cout<<"Mini Calculator v1\n\n";
                      cout<<multi1"x"multi2"="multiO"\n";                  
                      system("PAUSE");
                      goto mMenu;
        }
        
        //division
        if (mMenuc==2)
        {
                      //value 1
                      float div1;
                      system("cls");
                      cout<<"Mini Calculator v1\n\n";
                      cout<<"Please enter value 1:";
                      cin>>div1;
                      
                      //value 2
                      float div2;
                      system("cls");
                      cout<<"Mini Calculator v1\n\n";
                      cout<<"Please enter value 2:";
                      cin>>div2;
                      
                      //Output
                      float divO;
                      divO=div1/div2;
                      system("cls");
                      cout<<"Mini Calculator v1\n\n";
                      cout<<div1"/"div2"="divO"\n";                  
                      system("PAUSE");
                      goto mMenu;
        }
        
        //Exit
        if(mMenuc==3)
        {
                     break;
        }
        
        //failsafe 1
        if(mMenuc>=4)
        {
                     system("cls");
                     cout<<"ERROR: Incorrect input, restarting";
                     system("pause");
                     goto mMenu;
        }
        
        //failsafe 2
        if(mMenuc<=0)
        {
                     system("cls");
                     cout<<"ERROR: Incorrect input, restarting.";
                     system("pause");
                     goto mMenu;
        }
        return EXIT_SUCCESS;
    }
    Thx in advance

  2. #2
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    Code:
    :mMenu;
    This should be
    Code:
    mMenu:
    Code:
    cout<<div1"/"div2"="divO"\n";
    You can't string stuff together like that, try this:
    Code:
    cout<<div1<<"/"<<div2<<"="<<divO<<"\n";

    Code:
        if(mMenuc==3)
        {
                     break;
        }
    Change this to
    Code:
        if(mMenuc==3)
        {
                    return 0;
        }
    EDIT
    People may also advise against the use labels and system calls.

    EDIT 2
    I don't know if it was intentional or not but you spelt your name wrong.
    Nebuchadnezzar
    Last edited by MadCow257; 05-27-2005 at 08:17 PM.

  3. #3
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Code:
    int main(int argc, char *argv[])
    should be
    Code:
    int main(int argc, char argv[])

    Code:
    :mMenu;
    i don't even know why this is here
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  4. #4
    Never Exist Hermitsky's Avatar
    Join Date
    Jul 2004
    Posts
    149
    fixed, you'd better read some c books before write the code.
    and, don't use goto unless you have to.
    Code:
    //Mini calculator used for multiplication and division
    #include <cstdlib>
    #include <iostream>
    #include <cstdio>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        //ask for conversion of Multiplacation and Division
        :mMenu;
        system("cls");
        cout<<"Calculator Mini v1\n\n";
        cout<<"1. Multiplacation.\n";
        cout<<"2. Division.\n";
        cout<<"3. Exit.\n";
        int mMenuc;
        cout<<"\nYour decision (1,2,3):";
        cin>>mMenuc;
        
        //Multiplacation
        if (mMenuc==1)
        {
                      //value 1
                      float multi1;
                      system("cls");
                      cout<<"Mini Calculator v1\n\n";
                      cout<<"Please enter value 1:";
                      cin>>multi1;
                      
                      //value 2
                      float multi2;
                      system("cls");
                      cout<<"Mini Calculator v1\n\n";
                      cout<<"Please enter value 2:";
                      cin>>multi2;
                      
                      //Output
                      float multiO;
                      multiO=multi1*multi2;
                      system("cls");
                      cout<<"Mini Calculator v1\n\n";
                      cout<<multi1"x"multi2"="multiO"\n";                  
                      system("PAUSE");
                      goto mMenu;
        }
        
        //division
        if (mMenuc==2)
        {
                      //value 1
                      float div1;
                      system("cls");
                      cout<<"Mini Calculator v1\n\n";
                      cout<<"Please enter value 1:";
                      cin>>div1;
                      
                      //value 2
                      float div2;
                      system("cls");
                      cout<<"Mini Calculator v1\n\n";
                      cout<<"Please enter value 2:";
                      cin>>div2;
                      
                      //Output
                      float divO;
                      divO=div1/div2;
                      system("cls");
                      cout<<"Mini Calculator v1\n\n";
                      cout<<div1"/"div2"="divO"\n";                  
                      system("PAUSE");
                      goto mMenu;
        }
        
        //Exit
        if(mMenuc==3)
        {
                     break;
        }
        
        //failsafe 1
        if(mMenuc>=4)
        {
                     system("cls");
                     cout<<"ERROR: Incorrect input, restarting";
                     system("pause");
                     goto mMenu;
        }
        
        //failsafe 2
        if(mMenuc<=0)
        {
                     system("cls");
                     cout<<"ERROR: Incorrect input, restarting.";
                     system("pause");
                     goto mMenu;
        }
        return EXIT_SUCCESS;
    }

    blow me ... ...

  5. #5
    Registered User
    Join Date
    May 2005
    Posts
    41
    I know, I know I suck at coding but I have to start somewhere.

    OK, thx for all of your replies and help, also I Was reading a C++ book, however it was rather old, and as such alot of the code isnt compatible with my compiler (so the authors website said.)
    addressed to The Brain: unless you can tell me another way of allowing the user to return to the main menu, I think Ill have to stick with goto etc.

    And BTW, Nebbuchadnezzar IS spelt with 1 b, although Ive always thought it was 2, Nebuchadnezzar was Babylonian general and Nebuchadnezzar II had the hanging gardens of Babylon, one of the wonders of the ancient world, built for his wife. The ruins of Babylon can be found south of Baghdad.

    Again thank you for your help.
    Last edited by Nebbuchadnezzar; 05-27-2005 at 08:33 PM.

  6. #6
    Registered User Finchie_88's Avatar
    Join Date
    Aug 2004
    Posts
    154
    Instead of using the goto function, you could place the main menu in a function, so that it can be called later in your program. For example...
    Code:
    int main(...)
    {
    menu();
    return 0;
    }
    
    void menu()
    {
    // main menu goes here
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM
  4. Help with Postfix Calculator Project
    By hpy_gilmore8 in forum C Programming
    Replies: 5
    Last Post: 03-12-2003, 10:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21