Please help me with this while statement and looping

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
    int x,y,z,a,b,i;
    y = 2;
    z = 4;
    a = 6;
    b = 8;
    i = 0;
    int pattern = 0;
	char response;
	int sum;
    cout << "What is the following pattern?" << endl;
    cout << "y: " << y << endl;
    cout << "z: " << z << endl;
    cout << "a: " << a << endl;
    cout << "b: " << b << endl;
    cout << "i: ?" << endl;
    while (pattern != 2)
    {
        cout << "The pattern is: ";
        cin >> pattern;
        if (pattern != 2)
            cout << "Wrong, try again.\n";
        else
            break;
    }
    cout << "Good job, it is 2!" << endl;
    cout << "If the pattern continues, the variable i should equal: ";
    cin >> i;
    while (i != 10)
    {
        cout << "Incorrect, try again.\n";
        cout << "The variable i should equal: ";
        cin >> i;
    }
	cin.ignore();
    cout << "Correct, good job!" << endl;

	cout << " Now your ready for some addition right.....Y or N?";
	cin >> response;
	if (response == 'Y')
	{
		cout << " Great! What is a + b?" << endl;
		cin >> sum;
		while (sum != 14)
			cout << " Incorrect Try again! ";
		break;
	}
	
	else if (response == 'N')
	{
		cout << " You suck! close my program!";
		    cin.get();
			cin.get();
	}



I'm trying to make it so if you say Y you answer a math question but I don't know how to go about it.
closed account (zb0S216C)
This possibly (?):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
if( response == 'Y' )
{
    cout << " Great! What is a + b?" << endl;
   
    while( true )
    {
        cin >> sum;

        if( sum != 14 )
            cout << "Wrong answer";

        else break;
    }
}


Wazzak
Last edited on
Topic archived. No new replies allowed.