User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 402,797 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,893 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 392 | Replies: 12
Reply
Join Date: Jul 2008
Posts: 11
Reputation: greyghost86 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
greyghost86 greyghost86 is offline Offline
Newbie Poster

Re: making a simple c++ game

  #11  
Jul 23rd, 2008
Originally Posted by Salem View Post
    do{
    } while (choice != 'c' && choice != 'C');
This should be your code to start with, then you compile it to see what the result is. If it doesn't compile, then fix it.

Then your code becomes
    do{
        cout << "A: To Play the number guessing game." << endl;
        cout << "B: To Play the letter game." << endl;
        cout << "C: To quit program." << endl;
        cin >> choice;
    } while (choice != 'c' && choice != 'C');
Compile it again, and fix any new errors.

Then perhaps
    do{
        cout << "A: To Play the number guessing game." << endl;
        cout << "B: To Play the letter game." << endl;
        cout << "C: To quit program." << endl;
        cin >> choice;
    } while (choice != 'c' && choice != 'C');
    switch (choice) 
    {
        case 'A':
        case 'a':
        break;
    }
Notice how you can add just a few lines at a time, and it will compile.

When you've done this a few times, then test what you've written so far to make sure it actually works as expected. If it doesn't, then fix those before adding more code.

In particular, note that the { } are never left out of place, or unbalanced.


What you've done is code beyond your ability to deal with the compiler throwing the whole mess back at you, so instead you dump it on a message board for someone else to fix. This isn't a good long term strategy.


I am sorry I came to message board to ask for help on something. I thought that was what it was used for. also if I filled in my program they way you have it above.
    
do{
        cout << "A: To Play the number guessing game." << endl;
        cout << "B: To Play the letter game." << endl;
        cout << "C: To quit program." << endl;
        cin >> choice;
    } while (choice != 'c' && choice != 'C');
    switch (choice) 
    {
        case 'A':
        case 'a':
        break;
    }

It wouldn't have compiled right anyway cause I need the while after the switch like so.

    
do{
        cout << "A: To Play the number guessing game." << endl;
        cout << "B: To Play the letter game." << endl;
        cout << "C: To quit program." << endl;
        cin >> choice;
    
    switch (choice) 
    {
        case 'A':
        case 'a':
        break;
    }
} while (choice != 'c' && choice != 'C');

This works like a charm on my program. Sorry I dumped my problem on you.
Reply With Quote  
Join Date: Jul 2005
Posts: 1,104
Reputation: Lerner is a jewel in the rough Lerner is a jewel in the rough Lerner is a jewel in the rough Lerner is a jewel in the rough 
Rep Power: 9
Solved Threads: 144
Lerner Lerner is offline Offline
Veteran Poster

Re: making a simple c++ game

  #12  
Jul 23rd, 2008
Salem was trying to teach you a better way to fish, not just toss you a fish. Sometimes you're going to get a direct answer to answer a given problem, and sometimes you're going to get a better way to solve the problem in the first place. I hope you can enjoy both approaches.
Reply With Quote  
Join Date: Dec 2005
Posts: 3,411
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 21
Solved Threads: 387
Colleague
Salem's Avatar
Salem Salem is offline Offline
void main'ers are DOOMed

Re: making a simple c++ game

  #13  
Jul 24th, 2008
> Salem was trying to teach you a better way to fish
Exactly!
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 10:34 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC