Need help with first code.

Hi!
I just started learning C++ as my first programming language.
I started by writing my first code, but I ran into an issue. I'll leave the entire code below:

#include <iostream>

using namespace std;

int main()
{
// This part of code is for the input.
cout << "x + 2 = 4. how much is x?" << endl;
int x = 0;
cin >> x;
cout << x + 2 << endl;
int rez = 0
;cout << "did you answer honestly?" << endl;
cin >> rez;

if (rez = 1) {
cout << "you have 200 IQ!";
} else {
cout << "sorry! you will need to learn math!";
}
// Outputs the result.

return 0;
}
Change

if (rez = 1) {

to

if (rez == 1) {


= assignment
== comparison
Thanks! I hope my writing isn't too messy.
Last edited on
For readability, it's better to use code tags and formatted code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;

int main()
{
	cout << "x + 2 = 4. how much is x? ";

	int x {};
	cin >> x;
	cout << x + 2 << '\n';

	int rez {};
	cout << "Did you answer honestly (1 for yes, 0 for no)? ";
	cin >> rez;

	if (rez == 1)
		cout << "You have 200 IQ!\n";
	else
		cout << "Sorry! you will need to learn math!\n";
}

Yeah, I started learning C++ yesterday, so I have no clue, what are tags.
Welcome to C++!

tags are special sequences that inform how the text is to be displayed. For code this is:


[code]
//the code goes here
[/code]


Also you can select the formatted code and click '<>' on the right panel when editing.

See http://www.cplusplus.com/articles/z13hAqkS/

:)
Last edited on
Topic archived. No new replies allowed.