on line 53 it says menu is undeclared. but if i bought menu first then mcdonalds is undeclared. does anyone know how i can sort this out?

ty

#include <iostream>

using namespace std;

double money = 50.00;

void Mcdonalds()
{
     cout << "Welcome\n";
     cout << "How can i help you?\n\n";
     int mcdonalds;
     cout << "1.Eat \t £2.50\n";
     cout << "2.Drink \t £1.00\n";
     cout << "3.Buy 1/6 of Mcdonalds \t £20.000\n";
     cout << "4.Leave\n";
     cin >> mcdonalds;
     
     switch (mcdonalds)
     {
     case 1:
          if (money >= 2.50)
          {
                    cout << "You have eaten and are no longer hungery\t";
                    money = money - 2.50;
                    cout << "your money is: £" , money, "\n";
                    Mcdonalds();
                    }
                    else {
                         cout << "You can not afford this";
                         
                         Mcdonalds();
                         }
                         break;
     case 2:
          if (money >= 1.00)
          {
                    cout << "You are no longer thirsty";
                    money = money - 1.00;
                    cout << "your money is: £" , money, "\n";
                    Mcdonalds();
                    }
          else {
               cout << "you can not afford this";
               Mcdonalds();
               }
               break;
     case 3:
          Mcdonalds();
          break;
          
     case 4:
          
          Menu();
          break;
          }
    
}


void Menu()
{
           int menu;
           cout << "You are outside\n";
           cout << "What do you want to do?\n";
           cout << "\n\n";
           cout << "1. Mcdonalds\n";
           cout << "2. School\n";
           cout << "3. Work\n";
           cout << "4. Gym\n";
           cout << "5. JD\n";
           cin >> menu;
           
           switch (menu)
           {
                  case 1:
                       Mcdonalds();
                       break;
                
                }    
                }



     
     // home
     void Home()
    {
    cout << "You are at home\n";
    cout << "What do you want to do?\n";
    cout << "type either 1 or 2. numbers above 2 will also count as 2.\n";
    int home;
    cout << "1. sleep\n";
    cout << "2. leave home\n";
    cin >> home;
    
    switch (home)
    {
           case 1:
                cout <<"\nyou have slept\n\n";
                Home(); 
           break;
           
           case 2:
           break;
           
           default:
           break;
           }
}
            


int main ()
{


    cout << "Welcome to Real World\n";
    string name;
    cout << "whats your name? ";
    cin >> name; //name!!!!!
    cout << "\n\n";

    

    //home
    Home();

           
           //menu
           
           Menu();

           
           
    
    

    

 

system ("PAUSE");
return 0;   
}

You can declare a function without defining it if you replace the curly brackets and code with a semicolon:

void Menu();

void McDonalds()
{
    // ...
}

void Menu()
{
    // ...
}
commented: thanks +1

it still comes up with the same error

:(

Try this code:

#include <iostream>
#include <string>

using namespace std;

void Menu();

double money = 50.00;

void Mcdonalds()
{
    cout << "Welcome\n";
    cout << "How can i help you?\n\n";
    int mcdonalds;
    cout << "1.Eat \t £2.50\n";
    cout << "2.Drink \t £1.00\n";
    cout << "3.Buy 1/6 of Mcdonalds \t £20.000\n";
    cout << "4.Leave\n";
    cin >> mcdonalds;

    switch (mcdonalds)
    {
    case 1:
        if (money >= 2.50)
        {
            cout << "You have eaten and are no longer hungery\t";
            money = money - 2.50;
            cout << "your money is: £" , money, "\n";
            Mcdonalds();
        }
        else {
            cout << "You can not afford this";
            Mcdonalds();
        }
        break;
    case 2:
        if (money >= 1.00)
        {
            cout << "You are no longer thirsty";
            money = money - 1.00;
            cout << "your money is: £" , money, "\n";
            Mcdonalds();
        }
        else {
            cout << "you can not afford this";
            Mcdonalds();
        }
        break;
    case 3:
        Mcdonalds();
        break;
    case 4:
        Menu();
        break;
    }
}

void Menu()
{
    int menu;
    cout << "You are outside\n";
    cout << "What do you want to do?\n";
    cout << "\n\n";
    cout << "1. Mcdonalds\n";
    cout << "2. School\n";
    cout << "3. Work\n";
    cout << "4. Gym\n";
    cout << "5. JD\n";
    cin >> menu;

    switch (menu)
    {
    case 1:
        Mcdonalds();
        break;
    }    
}

// home
void Home()
{
    cout << "You are at home\n";
    cout << "What do you want to do?\n";
    cout << "type either 1 or 2. numbers above 2 will also count as 2.\n";
    int home;
    cout << "1. sleep\n";
    cout << "2. leave home\n";
    cin >> home;

    switch (home)
    {
    case 1:
        cout <<"\nyou have slept\n\n";
        Home(); 
        break;
    case 2:
        break;
    default:
        break;
    }
}

int main ()
{
    cout << "Welcome to Real World\n";
    string name;
    cout << "whats your name? ";
    cin >> name; //name!!!!!
    cout << "\n\n";

    //home
    Home();

    //menu
    Menu();

    system ("PAUSE");
    return 0;   
}

If it gives you the same error, you have bigger problems than some misplaced code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.