Probably really simple

Hey, I'm just starting out and I can't figure out why this won't work. No matter what I input it treats the first if statement like it's true. What am I missing here? Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;

int main()
{
	char Letter;
	cin >> Letter;
	if (Letter = 'A')
		cout << Letter;
	else
		cout << "Sorry. Fag.";
	return 0;
}
Use == instead of =
This is a common mistake, no worries :D

EDIT:
Guess I can explain why. == is the comparison operator, = is the assignment operator.

EDIT Dos:
Not that I care, but it may against forum rules (not to mention offensive to some people) to be using , uh derogatory remarks, even if it just random output in your code.
Last edited on
I would say it should be

if (Letter = A)

but It's also my first day learning C++

EDIT:

the above statement would make more sense
Last edited on
Awesome, thanks!
How I remembered this when I started was by saying it aloud at first. For example, if I saw:

int a = 0;

I would say "Int a equals zero"

If I saw

if(int a == 0);

I would say "If int a is equal to 0.

Not sure why, but this helped me keep em straight at first
Topic archived. No new replies allowed.