Help Me Please CPP problem
Results 1 to 3 of 3

Thread: Help Me Please CPP problem

  1. #1
    Senior Member
    Join Date
    Feb 2002
    Posts
    114

    Question Help Me Please CPP problem

    Hi all.
    I hope someone can help me with this problem i have.

    I am doing a CPP assignment for college and am having trouble getting my code to work and i dont know why.

    Anyway enclosed are the source code that i have developed so far in both CPP and TXT formats and the assignment guidelines (all zipped together)

    I got this assignment after studying CPP for two weeks (one 3 hour slot per week) the teacher is hopeless (very bright but not helpfull) he spends all his time on a wheely chair and scoots around the classroom filming the students on his digicam.

    Any help at all would be gratefully accepted

    Thanks

    Damien
    [pong][gloworange]665[/gloworange] Next door to the [glowpurple]devil[/glowpurple][/pong]

  2. #2
    Senior Member
    Join Date
    Jan 2002
    Posts
    227

    hope this helps

    I don't know if I understood what you want to know but here is the code... I hope it enough easy and short (but on the other side i tried to make the smallest changes to your code)because I don't know how far you get at school. If you want to input whole YES and NO instead of just Y or N use strcmpi command - it's not case sensitive so you won't have to do translation down case to upper case... For help of strcmpi use help in c++ If u have any question please let me know. Btw I made it pretty quick because I didn't have much time so if there are some mistakes please tell me about them.

    And here goes the code...
    #include <iostream.h>
    int elsejunk(int count);
    void maingame(); //predeclarations

    void main ()
    {
    start:
    maingame();
    char istring;
    cout<<"Another game?"<<endl;
    cout<<"Press Y to play another game"<<endl;
    cin>>istring;
    if ((istring=='Y')||(istring=='y'))goto start;
    }

    void maingame()
    {
    int num1 = 50, div1 = 0, hi = 100, lo = 0;
    char istring;

    cout<<"Think of an int number between 1 and 100."<<endl;
    cout<<"Lets play!"<<endl;
    cout<<"To all the questions please answer Y(for yes) or N (for no)..."<<endl;
    for (int count=1; count<=20; count++)
    {
    // goes=++;
    cout<<"Is your number "<< num1 <<"?"<<endl; //output
    cin>> istring; //get the answer for i string
    if ((istring=='Y')||(istring=='y')) //if input = Yes
    {
    cout<<"Your number is "<< num1 << endl; //Do this
    cout<<"It took "<< count <<" to guess this number"<<endl;
    break;
    }
    else if ((istring=='N')||(istring=='n'))
    {
    cout<<"Is your number higher then "<< num1<<"?"<<endl; //do this
    cin>> istring; //get the answer for i string
    if ((istring=='Y')||(istring=='y')) //if input = Yes so num1 = higher
    {
    //Higher code
    lo=num1;
    div1=(hi-num1)/2;
    num1=div1 + num1;
    }
    else if ((istring=='N')||(istring=='n')) //If input = No
    {
    //Lower code
    hi=num1;
    div1=(num1-lo)/2;
    num1=num1-div1;
    }
    else //if input doesn't = yes or no
    count = elsejunk(count);
    }
    else count = elsejunk(count);
    }

    }


    int elsejunk(int count)

    {
    cout << "In the game please enter only Y (for yes) Or N (for no)!!!!"<<endl;
    count--;
    return count; //this function just say to press Y or N and decrase the count;
    //decreasing count is here because player would press for example w many times
    //it would be counted as bad tries for computer... so that's why decraseing count...
    //result - only Y or N are counted as tries... hope someone get this)))

    }
    http://promote.opera.com/small/opera94x15.gif

    [gloworange]Sun7dots[/gloworange]

  3. #3
    Senior Member
    Join Date
    Feb 2002
    Posts
    114
    Thank you for your help it is very much appreciated the program works im just looking through it trying to understand what each thing does.

    Once again thanks for you help

    Damien
    [pong][gloworange]665[/gloworange] Next door to the [glowpurple]devil[/glowpurple][/pong]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •