If and else fail

Hello, i'm making a form of 'Quiz' program, with a menu and a point system.
But,
my promblem is that whenever i answer a question, the answer wil allways be correct. Help me with correct this.
Also, my point system won't work, i dont know why.
FACT: I will add more questions in soon, but i just want it to work with the first 3 question, then i will add more questions to the program.

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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include "Definers.h"


int main()
{
	//srand(static_cast<unsigned int>(time(0)));
	//srand (time(NULL));
	//CatKon = rand() % 3 + 1;
	Points == 0;
	system("CLS");
	cout<<"Category: \n \n"
		  "1. Office \n"
		  "2. Room \n"
		  "3. Bathroom \n"
          "4. Nersury Room \n"
	      "5. Living Room \n"
		  "  #Bodil    \n";
		  cin>>answer;
			  if(answer == 1)
			{
				{
					cout<<"_______________________________ \n"
						  "The choosed category is Office. \n";
					Sleep(2000);
					CatKonPoints == 0;
					CatKonStart:
		            srand (time(NULL));
				    CatKon = rand() % 3 + 1;
					system("CLS");
				}
		    if(CatKon == 1)
			    {
					string answer;
					cout<<"\n\n\n Translate: \n\n"
						  "-Chair- \n\n\n\n\n";
					cin>>CharAnswer;
					if (CharAnswer = "Stol" || "stol")
					{
						cout<<"Your guess was correct!";
						CatKonPoints + 10;
						Sleep(2000);
						CatKonPoints + 1; //Out of 15
						if(CatKonPoints == 3)
						{
							goto CatKonEnd;
						}
						system("CLS");
						goto CatKonStart;
					}
					else
					{
						cout<<"Your answer was incorrect. \n";
						system("CLS");
						Sleep(2000);
						CatKonPoints + 1; //Out of 15
						if(CatKonPoints == 3)
						{
							goto CatKonEnd;
						}
						goto CatKonStart;
					}

				}
			if(CatKon == 2)
				{
					string answer;
					cout<<"\n\n\n Translate: \n\n"
						  "-Desktop- \n\n\n\n\n";
					cin>>CharAnswer;
					if (CharAnswer = "Skrivebord" || "skrivebord")
					{
						cout<<"Your guess was correct!";
						CatKonPoints + 10;
						Sleep(2000);
						CatKonPoints + 1; //Out of 15
						if(CatKonPoints == 3)
						{
							goto CatKonEnd;
						}
						system("CLS");
						goto CatKonStart;
					}
					else
					{
						cout<<"Your answer was incorrect. \n";
						system("CLS");
						Sleep(2000);
						CatKonPoints + 1; //Out of 15
						if(CatKonPoints == 15)
						{
							goto CatKonEnd;
						}
						goto CatKonStart;
					}
				}

			if(CatKon == 3)
				{
					string answer;
					CatKon3:
					cout<<"\n\n\n Translate: \n\n"
						  "-Bookshelf- \n\n\n\n\n";
					cin>>answer;
					if (CharAnswer = 'Reol' || 'reol' || "Boghylde" || "boghylde" || "BogHylde" || "BOGHYLDE")
					{
						cout<<"Your guess was correct!";
						CatKonPoints + 10;
						Sleep(2000);
						CatKonPoints + 1; //Out of 15
						if(CatKonPoints == 15)
						{
							goto CatKonEnd;
						}
						system("CLS");
						goto CatKonStart;
					}
					else
					{
						cout<<"Your answer was incorrect. \n";
						Sleep(2000);
						CatKonPoints + 1; //Out of 15
						if(CatKonPoints == 15)
						{
							goto CatKonEnd;
						}
						system("CLS");
						goto CatKonStart;
					}

			    }
			
		  else
			    {
				    cout<<"Critical Error!";
			    }
			}
			CatKonEnd:
			cout<<"You got "<<Points<<" Points\n";
			if(Points == 0)
			{
				"You are terrible at this game! \n"
				"You should train ALOT more, \n"
				"on your english. \n";
			}
			if(Points<20)
			{
				"Not that awful \n"
				"You should train much more, \n"
				"on your english. \n";
			}
			if(Points>30)
			{
				"Not THAT bad. \n"
				"You should train more, \n"
				"on your english. \n";
			}
			
		  else
		  {
				cout<<"Critical Error!";
		  }
	system("PAUSE>nul");
	return 0;
}


Merry Christmas all!:3
ok I think here it is best to delete all the code you have and start again and do it right.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
//Basic Q & A example: 
#include <string>
#include <iostream> 

int main()
{
     int score = 0;  //Keep track of score
     std::string answer;  //User answer. 
     
     std::cout << "What is "yellow" in Welsh?\n"; 
     std::cin >> answer;

    if(answer == "melyn" || answer == "MELYN") //answer == on EVERY or. 
    {
          ++score; //One point for correct answer. 
    }
    else
    {
         std::cout << "WRONG!\n"; 
    }
    return 0; 
}


The key differences here:
-Absolutely no use of goto. DO NOT use goto.

-If statements with multiple conditions need the full condition written out each time.
1
2
3
4
5
6
7
if(condition == 1 || condition = 0 || condition = 2) //Correct
{
}

if(condition == 1 || 2 || 0) //Incorrect. The second and third conditions will always return true. 
{
}


-No use of system() anything.

-Is neatly indented to make it readable.

If you get something like this working, there are even better methods of making a Q & A program! But I suggest getting something basic working first.

Edit: Thanks ne555, fixed dem typos.
Last edited on
if i can't use system()
i cant stop the code runing.
How should i make a code without that?

I have made a simple one before.
Then i made a new simple one and started
to build it bigger and bigger, with ALOT more
details.
I did'nt post you this Definers.h
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
#include <iostream>
#include <Windows.h>
#include <ctime>
#include <time.h>
#include <math.h>
#include <string>
#define VK_C 0x43
#define EXITCONDITION 42
using namespace std;

//Default
int UserGuess;
int answer;
int Points;

//Categorys
int CatKon;
int CatRoom;
int CatBath;
int CatNers;
int CatLiv;
int Bodil;
char CharAnswer;

int CatKonPoints;
@Mats: careful
= is assignment
== is comparison

> if i can't use system()
> i cant stop the code runing.
¿ah? ¿why do you want to stop?
http://www.cplusplus.com/articles/iw6AC542/
ok you should not be using the .h version of these header files. So use <cmath> and <ctime> inplace of <math.h> and <time.h> in future. You also don't use any function from <math>, so you can get actually rid of that and since we're not using system(), you can get rid of <windows.h> too.

You should be declaring your variables inside the function that is using them, not globally as you have done here.

Bazzy and AngelHoof have good replies here: http://www.cplusplus.com/forum/beginner/22956/

Also, using namespace std; is not good practice. You should either type std::whatever as I have done in my example or type using for only what you are actually using, which in your case thus far would be.
1
2
3
using std::cin; 
using std::cout; 
using std::string; 


Good reading on this: http://www.cplusplus.com/forum/beginner/109940/

You might question my points in this post, but believe me, follow them now, from right now, rather than getting used to bad habits and suffering badly further down the line when everything starts going wrong.
Topic archived. No new replies allowed.