Please!I need some help!

This is a discussion on Please!I need some help! within the Game Programming forums, part of the General Programming Boards category; hi,how are you? I wanna understand in the code listed below what does 3 things mean? 1:char Exit='N'; What does ...

  1. #1
    killer
    Guest

    Question Please!I need some help!

    hi,how are you?
    I wanna understand in the code listed below what does 3 things mean?

    1:char Exit='N';
    What does it mean?

    2:while(toupper(Exit)!='Y')
    What does it mean??

    3:somewhere in the code we write: while(9>0)
    i just wanna know why do we put this?






    #include <iostream.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <time.h>

    int main()
    {

    char Exit='N';

    cout<<" *_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_ *_*_*_*_*_*_*_*_*\n";
    cout<<" *_*_*_*_*_*_*_*_*_*_*_*_Welcome to the Number machine*_*_*_*_*_*_*_\n";
    cout<<" *_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_ *_*_*_*_*_*_*_*_*\n";



    while(toupper(Exit)!='Y')
    {
    int Answer;
    int Count=1;
    int Number;

    srand((unsigned)time(NULL));
    Number=(rand()%99)+1;
    cout<<" \n";
    cout<<"\n";
    cout<<"\n";
    cout<<"1. I'm thinking of a number between 1 and 100\n";
    cout<<"What is my Number?";
    cin>>Answer;

    while (9>0)
    {

    if ((Answer<1) ||(Answer>100))
    {
    cout<<"Nope,i said a number between 1 and 100\n";
    Count=Count+1;
    }

    else if (Answer==Number)
    {
    cout<<"Good Job!"<<endl
    <<"You won in "<< Count <<" tries!!"<<endl;

    break;
    }


    //too high

    else if (Answer>Number)
    {
    cout<<"Too High!!\n";
    Count=Count+1;
    }

    //too low

    else if (Answer <Number)
    {
    cout<<"Too Low!!\n";
    Count=Count+1;
    }

    cout<<"What is my Number?";
    cin>>Answer;

    }

    cout<<"Now press 'Y' to quit or 'N' to play again:";
    cin>>Exit;

    }


    }

  2. #2
    wierd guy bart's Avatar
    Join Date
    Aug 2001
    Posts
    87
    char Exit='N';

    this creates a character object called Exit and sets it to 'N'. and

    while

    is a loop, and i think

    while(toupper(Exit)!='Y')

    means "loop while the variable Exit is Y"

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    1) you are right about that.
    2) not quite.... toupper makes a char upper case and != means not equal to so:-
    while(toupper(Exit)!='Y')
    means keep doing this while the upper case version of the value of exit is not equal to 'Y'
    3)while (9>0)...... this is always going to be true so this means loop forever.... alternatively it could have been written as while(1)
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

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