need some help with basic C++

This is a discussion on need some help with basic C++ within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm trying to make a simple calculatir(since I'm busy with C++ fo only 2 days) and it isn't working. ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    2

    need some help with basic C++

    Hi,
    I'm trying to make a simple calculatir(since I'm busy with C++ fo only 2 days) and it isn't working. I will post the code here. Could someone please tellme what's wrong?

    Code:
    #include <iostream>
    
    using namespace std;
    
    void optellen();
    void aftrekken();
    void vermenigvuldigen();
    void delen();
    
    int main()
     {
       int input;
        cout<<"1. optellen/n";  
        cout<<"2. aftrekken/n";
        cout<<"3. vermenigvuldigen/n";
        cout<<"4. delen/n";
        cout<<"5. afsluiten/n";
        cout<<"Uw keuze: ";
        cin>> input;
        switch ( input ) {
                         case 1:
                         optellen(           //here is one error
                                   {  int x;
                                      int y;
                                      cout<<"Voer 2 nummers in, en druk na ieder nummer op Enter: ";
                                      cin>> x >> y;
                                      cin.ignore();
                                      cout<<"het antwoord is: "<< x <<" + "<< y <<" = "<< x + y<<"/n";
                                      cin.get();
                                     }
                                     int count ( int x, int y )
                                     { 
                                     return x + y;
                                     } );
                                       
                                   break;  
                         case 2:
                          aftrekken( { int x;        //here is error #2
                                       int y;
                                       cout<<"voer 2 nummers in, en druk na ieder nummer op Enter: ";
                                       cin>> x >> y;
                                       cin.ignore();
                                       cout<<"het antwoord is: "<< x <<" - "<< y <<" = "<< x - y<<"/n";
                                       cin.get();
                                      }
                                      int subst ( int x, int y )
                                      { return x - y; }  );
                                      break;
                         case 3:
                          vermenigvuldigen( { int x;   // here is error#3
                                              int y;
                                              cout<<"voer 2 nummers in, en druk na ieder getal op Enter: ";
                                              cin>> x >> y;
                                              cin.ignore();
                                              cout<<"het antwoord is: "<< x <<" * "<< y <<" = "<< x * y<<"/n";
                                              cin.get();
                                             }
                                             int mult ( int x, int y )
                                             {return x * y; }  );
                                             break;
                         case 4:
                          delen( { int x;    //and here is last error
                                   int y;
                                   cout<<"Voer 2 nummers in, en druk na ieder nummer op Enter: ";
                                   cin>> x >> y;
                                   cin.ignore();
                                   cout<<"het antwoord is: "<< x <<" * "<< y <<" = "<< x / y<<"/n";
                                   cin.get();
                                  }
                                  int divide ( int x, int y )
                                  {return x / y; }  );
                                  break;
                         default:
                          cout<<"Fout, Ongeldige keuze. Start rekenmachine opnieuw/n";
                          break;
                         }
                         cin.get();
                         return 1;
                       }
    Thanks in advance!
    ramonnie

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Looks like you're trying to define functions inside the call parameter list of a function call.
    C++ doesn't understand any such thing.
    Kurt

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    And you need to reverse the slashs in your break signs.

  4. #4
    Registered User
    Join Date
    Jun 2007
    Posts
    2
    Okay, I get the problem. But is there any possibility to let it just work?

    Ramonnie

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,968
    But is there any possibility to let it just work?
    Yes, by fixing the problem. Duh
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    It looks like you're trying to return 1 from main(). Usually 0 is returned from main if no errors occured, whereas nonzero numbers such as 1 are reserved for error conditions.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,788
    As an example of what you need to do:
    Code:
    #include <iostream>
    
    using namespace std;
    
    void optellen();
    void aftrekken();
    void vermenigvuldigen();
    void delen();
    
    int main()
    {
        int input;
        cout<<"1. optellen/n";  
        cout<<"2. aftrekken/n";
        cout<<"3. vermenigvuldigen/n";
        cout<<"4. delen/n";
        cout<<"5. afsluiten/n";
        cout<<"Uw keuze: ";
        cin>> input;
        switch ( input )
        {
        case 1:
            optellen();
            break;  
    
        ...
    
        cin.get();
        return 0;
    }
    
    void optellen()
    {
        int x;
        int y;
        cout<<"Voer 2 nummers in, en druk na ieder nummer op Enter: ";
        cin>> x >> y;
        cin.ignore();
        cout<<"het antwoord is: "<< x <<" + "<< y <<" = "<< x + y<<"/n";
        cin.get();
    }
    Also:
    Code:
     int x;    //and here is last error
        int y;
        ...
    
        cout<<"het antwoord is: "<< x <<" * "<< y <<" = "<< x / y<<"/n";
        cin.get();
    }
    int divide ( int x, int y )
    {return x / y; }  );
    Be careful here as this is likely to not give you what you want as an answer. Integer division produces an integer result so 8 / 6 is 1 instead of 1.3333... You probably need to use floating point variables here if you want to get the answer.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 09:28 AM
  2. what are your thoughts on visual basic?
    By orion- in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-22-2005, 04:28 AM
  3. visual basic vs C or C++
    By FOOTOO in forum Windows Programming
    Replies: 5
    Last Post: 02-06-2005, 07:41 PM
  4. Basic Graphics programming in C, please help
    By AdRock in forum Game Programming
    Replies: 3
    Last Post: 03-24-2004, 10:38 PM

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