Combining nested ifs with multiway ifs?

Hi, everyone! I need a lot of help with my program that I'm writing for my gen ed compsci class. I'm trying to combine multiway and nested if statements, if that's possible. For instance (and this is an arbitrary example):

1
2
3
4
5
6
7
8
9
10
11
if (letter=C)
  if (price=300)
    cout << "You spent $300 on C."
  if (price=400)
    cout << "You spent $400 on C."

if (letter=D)
  if (price=300)
    cout << "You spent $300 on C."
  if (price=400)
    cout << "You spent $400 on D."


However, if I try to put in D for the letter input and 300 for the price input, it'll say, "You spent $300 on C" even though I put D for the letter. How do I get it to jump down to the D? Or, if possible, how would I use a switch statement in this situation?

Thank you very much from a psychology major who has endless admiration for people who are good at this kind of stuff.
Btw, you're doing it wrong.

It should be:

if(letter == 'C')

You need to put the char between ' '.

You can't use one equal sign when comparing two things, you're not comparing them, you're assigning them to each other. So that won't work.

Post your whole code to help you better.
Last edited on
Topic archived. No new replies allowed.