-2

My homework program is supposed to contain a menu with a couple of options, first one is a guessing game, second, printing all cards in a deck 3…etc. (See the menu below). I have started writing some code and I have tested partial bits of the code and they have been working. Now with the whole program as such below I can’t execute the program. I would appreciate if someone could take a bit of their time and help with the problems and perhaps the rest of the must-include programs. The following error messages keep coming up:

Severity  Code    Description Project File    Line    Suppression State
Error (active)  E0120   return value type does not match the function type  ConsoleApplication1 C:\Users\Ingrid\C++\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp 163 
___________________________________________
Severity    Code    Description Project File    Line    Suppression State
Error (active)  E0020   identifier "settings1_Menu" is undefined    ConsoleApplication1 C:\Users\Ingrid\C++\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp 191 
____________________________________________
Severity    Code    Description Project File    Line    Suppression State
Error (active)  E0020   identifier "settings2_Menu" is undefined    ConsoleApplication1 C:\Users\Ingrid\C++\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp 195 

Severity  Code    Description Project File    Line    Suppression State
Error (active)  E0020   identifier "settings3_Menu" is undefined    ConsoleApplication1 C:\Users\Ingrid\C++\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp 199 

Severity  Code    Description Project File    Line    Suppression State
Error   C1010   unexpected end of file while looking for precompiled header. Did you forget to add '#include "pch.h"' to your source?   ConsoleApplication1 c:\users\ingrid\c++\consoleapplication1\consoleapplication1\consoleapplication1.cpp 219 
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <stdio.h>
#include <stdlib.h>     /* Imports srand and rand for the random generator in guess */
//*#include <stdafx.h>*//

using namespace std;

//*void guess_Menu();
//void card_Menu();
//void leap_Menu();
//void func_Menu();
//void settings_Menu;
//*void menu_check();

void main()
{
    int menu;

    cout << "***************************************************************************\n";
    cout << "***************************************************************************\n";
    cout << "####             Please Select From The Following Menu:              ######\n";
    cout << "####  Press 1 to play a guessing game                                ######\n";
    cout << "####  Press 2 to print all cards in a deck                           ######\n";
    cout << "####  Press 3 to display the leap year                               ######\n";
    cout << "####  Press 4 to calculate the function y = f(x)                     ######\n";
    cout << "####  Press 5 to check the settings (included color and language)    ######\n";
    cout << "####  Press 6 to exit the program                                    ######\n";
    cout << "***************************************************************************\n";
    cout << "***************************************************************************\n";
    cin >> menu;

    switch (menu)
    {
    case 1:
        guess_Menu();
        break;

    case 2:
        card_Menu();
        break;

    case 3:
        leap_Menu();
        break;

    case 4:
        func_Menu();
        break;

    case 5:
        settings_Menu();
        break;

    case 6:
        exit(0);
        break;

    default:
        std::cout << "|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|\n";
        std::cout << "|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|\n";
        std::cout << "|          INVALID NUMBER - CHOOSE FROM 1 - 6      |\n";
        std::cout << "|__________________________________________________|\n";
        std::cout << " \t\t\t    PRESS ENTER TO CONTINUE ";
        cin.ignore(std::numeric_limits<streamsize>::max(), '\n');
        cin.get();
        main();
    }

    system("pause");
}

void guess_Menu()
{
    int RandomNumber = rand() % 50 + 1; // to set the random number between 1-50
    int guesst = 15; // guess attempts as guesstaken or "guesst"
    int guess;
    const int Hnum = 50;
    const int Lnum = 1;

    void Again();
    {
        int decision = 0;
        bool TryAgain = true;
        char y;
        char Y;
        char n;
        char N;
    }

    cout << "Guess the random number between 1 and 50!\n";

    while (true)
    {
        cout << "You have " << guesst << " attempts remaining\n";
        cout << "Enter a number: ";
        cin >> guess;
        cin.ignore();
        cout << '\n';

        if (guess == RandomNumber)
        {
            cout << "Congratulations, you won: " << RandomNumber << "!";
            cout << "Would you like to play again y or n?";
            cin.get();
            void Again();
        }
        else if (guess < RandomNumber)
        {
            cout << "That guess is too low!\n";
        }
        else if (guess > RandomNumber)
        {
            cout << "That guess is too high!\n";
        }
        else if (guess > Hnum || guess < Lnum)
        {
            cout << "Guess must be lower than 50 and higher than 1, Try again\n";
            cin.get();//remove this to count guesses that are outside the 1-50
        }
        guesst--;

        if (guesst == 0)
        {
            cout << "You did a lowzy work trying to guess the number. The correct number was... " << RandomNumber << "!";
            cout << "\n";
            cin.get();
            void Again();
        }
    }
}


void card_Menu()
{
    printf("Hello World!");
}

void leap_Menu()
{
    int year;

    cout << "Enter a year: ";
    cin >> year;

    if (year % 4 == 0)
    {
        if (year % 100 == 0)
        {
            if (year % 400 == 0)
                cout << year << " is a leap year.";
            else
                cout << year << " is not a leap year.";
        }
        else
            cout << year << " is a leap year.";
    }
    else
        cout << year << " is not a leap year.";

    return 0;
}



void func_Menu()
{

    cout << "Blabla\n";
}



void settings_Menu()
{
    int menu;
    cout << "¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤\n";
    cout << "||          Please Select From The Following Menu           ||\n";
    cout << "||  1. Settings, choose this to change color                ||\n";
    cout << "||  2. Settings, choose this to language                    ||\n";
    cout << "||  3. Exit the program                                     ||\n";
    cout << "||   <------------------            ------------------>     ||\n";
    cout << "||__________________________________________________________||\n";
    cin >> menu;

    switch (menu)
    {
    case 1:
        settings1_Menu();
        break;

    case 2:
        settings2_Menu();
        break;

    case 3:
        settings3_Menu();
        break;

    default:
        cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n";
        cout << "§                                                §\n";
        cout << "^      INVALID NUMBER - CHOOSE FROM 1 - 3        §\n";
        cout << "^________________________________________________^\n";

        cin.ignore(std::numeric_limits<streamsize>::max(), '\n');
        cin.get();
        main();
    }
}
Max Langhof
  • 23,383
  • 5
  • 39
  • 72
EdDoge
  • 1
  • 2
  • 2
    All functions need to be declared before they can be used. It seems that you had the declarations at some point but decided to comment them out for some reason. Do you remember why you did that? – R Sahu Apr 09 '19 at 17:10
  • 1
    I dont know where the first error is (you should know because the error message contains the line number), but take `leap_Menu()` for example, you declare it to return nothing yet you return something – 463035818_is_not_an_ai Apr 09 '19 at 17:11
  • 1
    Calling `main()` yourself is undefined behavior. Don't do that, put the code in `main` into a different function and call that one if you need to. – Max Langhof Apr 09 '19 at 17:12
  • btw I doubt anybody knows who Ingrid is, but I would try to make the messages a bit more anonymous ;) – 463035818_is_not_an_ai Apr 09 '19 at 17:12
  • `void Again();` also does certainly not do what you probably think it does. And the block that follows is pointless. Try enabling more warnings in your compiler, it tends to notice this stuff. – Max Langhof Apr 09 '19 at 17:14
  • 2
    as a general advice, write less code and test more. A good balance is to write a single line and then only write the next one when you are absolutely certain that the code does what you expect. otherwise you just pile up bugs – 463035818_is_not_an_ai Apr 09 '19 at 17:17
  • Also, what do you expect `settings2_Menu()` to do? You didn't write any code for it, so the compiler tells you (quite clearly) that it has no idea what you want to do there. – Max Langhof Apr 09 '19 at 17:17
  • 1
    In c++ you must never call `main` and it's return type must be `int` (not `void`). – François Andrieux Apr 09 '19 at 17:46
  • ***unexpected end of file while looking for precompiled header. Did you forget to add '#include "pch.h"' to your source? ConsoleApplication1*** This error tells you exactly what to do. Make sure `pch.h` is the first include in the listed source file. Although you may want to just disable Precompiled Headers instead: https://stackoverflow.com/questions/7261707/how-to-avoid-precompiled-headers – drescherjm Apr 09 '19 at 17:54
  • I commented these earlier, sorry sent the worng version, the fuctions should be declared, but thanks! :) – EdDoge Apr 09 '19 at 19:14
  • But could someone maybe help me with the card problem, i should be able to print out a single deck of cards. Is there a fast way to do this or how should i approche the problem? Thanks in advance! – EdDoge Apr 09 '19 at 19:23

2 Answers2

0

Error 1: line 163

return 0; for a void function.

Error 2-4: Line 191, 195, 199

settings1_Menu()
settings2_Menu()
settings3_Menu()

are not defined.

Exactly as the errors read.

Not sure about the precompiled headers issue, I haven't really worked with them at all, and that error isn't in my VS2015.

Also, you have your function declarations commented out

//*void guess_Menu();
//void card_Menu();
//void leap_Menu();
//void func_Menu();
//void settings_Menu;
//*void menu_check();

Blocking compilation of the definitions, the settings_Menu there needs to be settings_Menu(), and menu_check() is undefined.

Tzalumen
  • 652
  • 3
  • 16
0

You have an error in the lead_menu function

void leap_Menu()
{
    ...
    return 0;
}

You also have all your prototypes commented out. So when the compiler reaches a function call, it doesn't know what the function is. If you don't want to use prototypes, look into in-line functions