If issues

Write your question here.
I am having issues keeping the "correct/incorrect" statements from being output in the wrong places
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <cstdlib>
#include <iostream> 
using namespace std;

int main()
{
	int aanswer;
	int option;
	int mlevel;
	int dlevel;
	int slevel;
	int alevel;
	int choice;
	int key;
	int answer;

  do{ //do-while loop starts here.that display menu again and again until user select to exit program
   
     //Displaying Options for the menu
    cout << "Please choose one of the following options:" << endl;
				cout << " [1] Addition" << endl;
				cout << " [2] Subtraction" << endl;
				cout << " [3] Multiplication" << endl;
				cout << " [4] Division" << endl;
				cout << " [5] Quit" << endl;
			
				
    
     cin >> key;  // taking option value as input and saving in variable "option"
     
     if(key == 1) // Checking if user selected option 1
     {
				cout << " level [1] " << endl;
				cout << " level [2] " << endl;
				cout << " level [3] " << endl;
				cout << " level [4] " << endl;
				cin >> alevel;
       
     }

     else if(key == 2) // Checking if user selected option 2
     {
			cout << " [1] " << endl;
				cout << " [2] " << endl;
				cout << " [3] " << endl;
				cout << " [4] " << endl;
				cin >> slevel;
     }
     else if(key == 3) // Checking if user selected option 3
     {
				cout << " [1] " << endl;
				cout << " [2] " << endl;
				cout << " [3] " << endl;
				cout << " [4] " << endl;
				cin >> mlevel;
     }
     else if(key == 4) // Checking if user selected option 4
     {
				cout << " [1] " << endl;
				cout << " [2] " << endl;
				cout << " [3] " << endl;
				cout << " [4] " << endl;
				cin >> dlevel;
     }
    
  
				if (key ==1){ 
					if (alevel ==1){
						answer = 2;
						cout<< "1 + 1 = "<<"? ";
					cin >> aanswer;}
				if (aanswer==aanswer){
						cout << "correct ";}
				else if(aanswer!=answer){
			//if (aanswer!=answer){
					cout << "incorrect ";}
				
					if(alevel ==2){
						answer = 3;
						cout<< "1 + 2 = "<<"? ";
					cin >> aanswer;}
				if (aanswer==answer){
						cout << "correct ";
						}
					
				else if(aanswer!=answer){
					cout << "incorrect ";
					}
					
					if (alevel ==3){
						answer = 4;
						cout<< "1 + 3 = "<<"? ";
					cin >> aanswer;}
			if (aanswer==answer){
						cout << "correct ";}
			else if(aanswer!=answer){
			
					cout << "incorrect ";
					}
					
					if (alevel ==4){
						answer = 1;
				cout<< "1 + 0 = "<<"? ";
					cin >> aanswer;}
			if (aanswer == answer){
			cout << "correct ";}
				else if(aanswer!=answer){
					cout << "incorrect ";}
			
				}
					}while(key != 5);  //condition of do-while loop
   		
						
   return 0;
}
http://www.cplusplus.com/forum/general/209384/

You already have a thread over there.

What do you mean by:
I am having issues keeping the "correct/incorrect" statements from being output in the wrong places


Do you mean you want a new line after the incorrect / correct? If that's the case, you need to make a new line after outputting correct / incorrect.

Edit: Change the else if -> else
Last edited on
Thanks for that tip, appreciated.
I get a output like this...
Please choose one of the following options:
[1] Addition
[2] Subtraction
[3] Multiplication
[4] Division
[5] Quit
1
level [1]
level [2]
level [3]
level [4]
2
incorrect 1 + 2 = ? 3
correct correct correct Please choose one of the following options:
[1] Addition
[2] Subtraction
[3] Multiplication
[4] Division
[5] Quit
1
level [1]
level [2]
level [3]
level [4]
4
correct correct correct 1 + 0 = ? 1
correct Please choose one of the following options:
[1] Addition
[2] Subtraction
[3] Multiplication
[4] Division
[5] Quit
trying to eliminate the needless "corrects and incorrects"
You misplaced your curly brackets. Line 72 change to if (aanswer==answer)

http://www.cplusplus.com/forum/general/209384/

Refer back to this thread for the curly bracket placement.
Last edited on
Topic archived. No new replies allowed.