Results 1 to 30 of 35

Thread: What is wrong with this code (C++)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Time Lord Member The_Doctor's Avatar
    Join Date
    Oct 2004
    Location
    The TARDIS
    Posts
    2,040

    Default What is wrong with this code (C++)

    For a peice of coursework for my uni course I have to make a simple game.

    I not very experienced with C++.

    There are 3 difficulty levels in it, each one inside a loop which will contain the rest of the game. In this code I am testing it to see if the loops work.

    #include <iostream.h>

    int main()
    {
    bool Easy;
    bool Medium;
    bool Hard;
    int Option;

    std::cout<< "Game intructions\n";
    std::cout<< "Please select a difficulty level\n";
    std::cout<< "1=Easy\n";
    std::cout<< "2=Medium\n";
    std::cout<< "3=Hard\n";
    std::cout<< "4=Quit\n";
    std::cin>> Option;

    if (Option == 1) {
    Easy = true;
    }

    if (Option == 2) {
    Medium = true;
    }

    if (Option == 3) {
    Hard = true;
    }

    if (Option == 4) {
    return 0;
    }

    while (Easy == true);
    {
    cout<< "Easy test works\n";
    Easy = false;
    }

    while (Medium == true);
    {
    cout<< "Medium test works\n";
    Medium = false;
    }

    while (Hard == true);
    {
    cout<< "Hard test works\n";
    Hard = false;
    }
    return 0;
    }
    When I press 1 nothing happens.
    When I press 2 it says "Easy Test Works".
    When I press 3 it says "Easy Test Works", then "Medium Test Works".
    Pressing 4 does end the program.

    I have no idea way this is happening.
    Last edited by The_Doctor; 11-22-2006 at 16:52.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Single Sign On provided by vBSSO