Thread: Beginning functions

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    20

    Beginning functions

    Hello, so I am getting into the basics of functions and having a little trouble with my program.

    Code:
    
    
    #include <iostream>
    using namespace std;
    
    
    
    void func1();
    void func2();
    void func3(int);
    
    
    int main ()
    {
            int choice;
            
            
            cout << "Input a 1 if you want a party" << endl;
            cout << "Input a 2 if you don't want a party\n" << endl;
            cout << "Please input your choice now: ";
            cin >> choice; 
            cout << endl;
     
                   if (choice == 1)
                   {
                      func1();
                   }
                   else if (choice == 2)
                   {
                      func2();
                   }
                   else 
                   {
                        while (choice != 1 && choice != 2)
                        {
                             func3(choice);
                             {
                                 if (choice == 1)
                                 {
                                    func1();
                                 }
                                 else if (choice == 2)
                                 {
                                    func2();
                                 }
                              }
                          }    
                     }
                   
                   return 0;
    }
    
    void func1()
    {
         cout << "You want a party" << endl;
    }
    void func2()
    {
         cout << "You don't want a party" << endl;
    }
    void func3(int reenter)
    {
         cout << "Invalid entry. Must enter a 1 or a 2. Re-enter your choice: ";
         cin >> reenter;
    }
    When I enter a number other than 1 or 2 it ask to re-enter like it should but then no matter what number I enter (even a 1 or 2) it just keeps asking me to re-enter a number.

    What is wrong that this keeps happening?
    Last edited by theCanuck; 04-06-2011 at 07:05 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with functions
    By jusfry01 in forum C Programming
    Replies: 2
    Last Post: 05-22-2010, 06:25 PM
  2. Functions calling other functions.
    By kbro3 in forum C++ Programming
    Replies: 2
    Last Post: 12-27-2009, 12:10 AM
  3. Compiling C in Visual Studio 2005
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 04:25 AM
  4. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  5. Attaching functions to a class/struct
    By VirtualAce in forum Tech Board
    Replies: 2
    Last Post: 08-04-2003, 10:56 AM