Thread: Another Problem

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    21

    Another Problem

    I have now added a switch statement to the program below and when I try to compile it says 'MenuChoice undefined please use this function first', any ideas?

    Code:
    #include <iostream>
    
    int MenuAndMenuChoice();
    double Add();
    
    int main()
    {
        
        MenuAndMenuChoice();
        
        switch (MenuChoice)
        {
              
              case 1: Add();
              
        }
        
        std::cin.get();
        return 0;
    }
    
    int MenuAndMenuChoice()
    {
        
        int MenuChoice;
        
        std::cout << "1.Add\n";
        std::cout << "2.Subtract\n";
        std::cout << "3.Multiply\n";
        std::cout << "4.Divide\n";
        std::cout << "5.Circle Area\n";
        std::cout << "6.Circle Circumference\n";
        std::cout << "7.Exit\n\n";
    
        std::cout << "What would you like to do? ";
        std::cin >> MenuChoice;
        
        return MenuChoice;
        
    }
    
    double Add()
    {    
         
        double FirstNumber, SecondNumber, AddAnswer;
         
        std::cout << "What is the first number: ";
        std::cin >> FirstNumber;
        std::cin.ignore(80,'\n');
        
        std::cout << "What is the second number: ";
        std::cin >> SecondNumber;
        std::cin.ignore(80,'\n');
        
        AddAnswer = FirstNumber + SecondNumber;
        
        return AddAnswer;
        
    }

  2. #2
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    sure
    you could do
    Code:
    int main()
    {
        int MenuChoice;
        MenuChoice = MenuAndMenuChoice();
        switch (MenuChoice)
    or
    Code:
    int main()
    {
        switch (MenuAndMenuChoice())

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    21
    Never thought of that, thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM