Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 30th, 2005, 5:23 PM   #1
zero771
Programmer
 
Join Date: Nov 2005
Posts: 37
Rep Power: 0 zero771 is an unknown quantity at this point
running error

I am making that guessing game someone said to make but for some reason it won't appear.

#include <iostream>
using namespace std;

int main ()
{
    int n, g, t; 
    n = 43;
        
    cout << "Welcome to the guessing game! \nThe number I am thinking of is between 1 and 100.";
    cout << "Enter the number you wish to guess.\n";
    cin >> g;
    
    while (g != n) {
    cout << "Guess again! You have attempted to guess " << t << " times.";
    }    
}
__________________
looking for a teacher, i'm willing to learn any language
- my master is jayme
zero771 is offline   Reply With Quote
Old Nov 30th, 2005, 5:49 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Well, what do you want to loop? It's not just the "you were wrong" message, is it?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Nov 30th, 2005, 5:57 PM   #3
zero771
Programmer
 
Join Date: Nov 2005
Posts: 37
Rep Power: 0 zero771 is an unknown quantity at this point
well its a guessing game, so its supposed to say you are wrong guess again
__________________
looking for a teacher, i'm willing to learn any language
- my master is jayme
zero771 is offline   Reply With Quote
Old Nov 30th, 2005, 5:59 PM   #4
LOI Kratong
Professional Programmer
 
Join Date: May 2005
Location: Woo - Boot Sector!
Posts: 294
Rep Power: 4 LOI Kratong is on a distinguished road
the input is not in the loop so it will just repeat the message continuously unless the first guess is correct
__________________
www.heldtogether.co.uk
LOI Kratong is offline   Reply With Quote
Old Nov 30th, 2005, 6:00 PM   #5
zero771
Programmer
 
Join Date: Nov 2005
Posts: 37
Rep Power: 0 zero771 is an unknown quantity at this point
oooh! i forgot to add the guess factor.... oops
__________________
looking for a teacher, i'm willing to learn any language
- my master is jayme
zero771 is offline   Reply With Quote
Old Nov 30th, 2005, 6:02 PM   #6
jayme
Professional Programmer
 
jayme's Avatar
 
Join Date: Nov 2005
Location: Canada
Posts: 495
Rep Power: 0 jayme is an unknown quantity at this point
Send a message via MSN to jayme
here are my "hints":

1. Give an integer value to t
2. the program will repeat
    while (g != n) {
    cout << "Guess again! You have attempted to guess " << t << " times."; }
until the number is guessed, look over this and post back how you will guess the number a second time.

3. include your 't' integer in that loop.
__________________

Quote:
Originally Posted by Mohamed Jihad
Durka durka!
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it.

Download Code::Blocks now!
jayme is offline   Reply With Quote
Old Nov 30th, 2005, 6:06 PM   #7
zero771
Programmer
 
Join Date: Nov 2005
Posts: 37
Rep Power: 0 zero771 is an unknown quantity at this point
okay i added the guess factor... it is still not appearing on startup

 #include <iostream>
using namespace std;

int main ()
{
    int n, g, t; 
    n = 43;
    t = 5;
        
    cout << "Welcome to the guessing game! \nThe number I am thinking of is between 1 and 100.";
    cout << "Enter the number you wish to guess.\n";
    cin >> g;
    
    while (g != n) {
    cout << "Guess again! You have attempted to guess " << t << " times.";
    cin >> g;
    }
    
    cout << "Congratulations! You have guessed the correct number: " << n << ".\n";
    cout << "Thank you for participating in my guessing game.";
            
    return 0;
        
}

the 5 by the way is just a random number (because i still have to learn how to read/write a file)
__________________
looking for a teacher, i'm willing to learn any language
- my master is jayme
zero771 is offline   Reply With Quote
Old Nov 30th, 2005, 6:09 PM   #8
jayme
Professional Programmer
 
jayme's Avatar
 
Join Date: Nov 2005
Location: Canada
Posts: 495
Rep Power: 0 jayme is an unknown quantity at this point
Send a message via MSN to jayme
get on msn, i added you.. i dont understand what you mean by appearing on startup. Works fine for me, except that you need to fix a few little problems, and the t = t +1 is missing
__________________

Quote:
Originally Posted by Mohamed Jihad
Durka durka!
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it.

Download Code::Blocks now!
jayme is offline   Reply With Quote
Old Nov 30th, 2005, 6:10 PM   #9
zero771
Programmer
 
Join Date: Nov 2005
Posts: 37
Rep Power: 0 zero771 is an unknown quantity at this point
once i figure out how to get online on msn... i will
it is rejecting my logon, says something about my internet connection....
__________________
looking for a teacher, i'm willing to learn any language
- my master is jayme
zero771 is offline   Reply With Quote
Old Nov 30th, 2005, 6:15 PM   #10
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
First of all, what's with the one-letter variables? You should know what a variable contains based on its name.

Next, you're not allocating anything to g. For all you know, it might have the number 43 already in it.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:33 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC