How to go to a previous line

This is a discussion on How to go to a previous line within the C++ Programming forums, part of the General Programming Boards category; So here's what I've made so far: Code: #include <iostream> using namespace std; int main() { int wheretogo; int psactivity; ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    10

    Question How to go to a previous line

    So here's what I've made so far:

    Code:
    #include <iostream>
    
    using namespace std;
    int main()
    
    {
        int wheretogo;
        int psactivity;
        int pcactivity;
        
        cout<<"You are in a house with a PC and PlayStation 3 with two games. What do you do?\n\n";
        cout<<"\nGo to the PlayStation 3 (1)\n\n";
        cout<<"\nGo to the PC (2)\n\n";
        cin>>wheretogo;
        cin.ignore();
        if (wheretogo == 1 ) {
                      cout<<"\nYou go to the PlayStation and boot it up.\n\n";
                      cout<<"\nCheck the PlayStation Store (1)\n\n";
                      cout<<"\nCheck the available games(2)\n\n";
                      cin>>psactivity;
                      cin.ignore();
                      }
        if (wheretogo == 2 ) {
                      cout<<"\nYou go to the PC and boot it up.\n\n";
                      cout<<"\nGo on the internet (1)\n\n";
                      cout<<"\nPlay Portal (2)\n\n";
                      cin>>pcactivity;
                      cin.ignore();
                      }
                      
    }
    Just some random text "game" I made. Here's the problem: I want an option to go back. Let's say the user chose go the playstation and use the playstation store or something, how can I include the option to go back and use the PC instead after he chose to go to the playstation?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You will need some form of loop, that takes you back to the first "what do you want to do" question.

    Of course, if you are actually going to make a text-adventure game, you probably want to have a data-structure that describes the options of what to do and where you can go from here, rather than using "code" to describe what you can and can't do at any given stage.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 11:17 AM
  2. Finding carriage returns (\c) in a line
    By JizJizJiz in forum C++ Programming
    Replies: 37
    Last Post: 07-19-2006, 06:44 PM
  3. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM
  4. SSCANF help
    By mattz in forum C Programming
    Replies: 7
    Last Post: 12-10-2001, 04:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21