Need help with the for loop

Hi, so I'm new to coding and I have an assignment where we need to design code for a guessing game involving days months and years. There's more to this but I'm not sure if I'm doing the for loop correctly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
void
GAME::GUESS_DAY()
{
 int USER_GUESS=0;
 int i;
 int FOUND_DAY=0;
 int REMAINING_CHANCES;
 int RETURN_VALUE=0;
    
 cout<< "CAN YOU GUESS WHICH DAY I WAS BORN," <<NAME<< "?" <<endl;
 cout<< " (YOU HAVE " << NOOF_CHANCES << " CHANCES) <<endl;

 REMAINING_CHANCES = NOOF_CHANCES -1;
 for (i=0; i < NOOF_CHANCES && FOUND_DAY==0; i++)
 {
    cin>> USER_GUESS;
    RETURN_VALUE = CHECK_USER_ENTRY(1, 31, USER_GUESS);
    
    if (RETURN_VALUE == -1)
    {
        cout<< "error message"<<endl;
    }
    else if (RETURN_VALUE == 1 && USER_GUESS == SECRET_DAY)
    {
         cout<<" wow we are born on the same day" <<USER_GUESS_DAY<<endl;
         FOUND_DAY; 


IM NOT SURE HOW TO END THE LOOP
I WROTE: FOUND_DAY;
If there isn't enough information about this let me know
Last edited on
It looks like you are...

If you need more assistance there is this nice tutorial here:
http://www.cplusplus.com/doc/tutorial/

Edit: I'm sorry, I somehow miss-read your question, lol.

Edit: Here's the specific tutorial page you might want to look at:
http://www.cplusplus.com/doc/tutorial/control/

Hope this helps,

~Hirokachi
Last edited on
closed account (LA48b7Xj)
You really like caps :)

I wouldn't have the FOUND_DAY in the loop condition, you could break out of the loop when you have found the day.
1
2
3
4
5
6
7
8
for (int i=0; i < NOOF_CHANCES; i++)
{
    if(FOUND_DAY == true)
    {
        //do whatever
        break;
    }
}

closed account (z0MN6Up4)
Were you guys able to figure this problem out, I am having the same problem with a similar program.
1
2
3
bool foo = false;

foo;

A name of variable alone in a statement, like the foo in line 3, does nothing.
You have to change the value of the variable. Assign a new value to it.
Topic archived. No new replies allowed.