if ' else statement

Hi everyone, this is my first shot at C++ and this problem is skullcrushing
i tried to fill it with

{
if (residence = O )
taxRate = 0;
else (residence = I )
taxRate = .05;
}
--------------------------------------
But the program wont compile.

here's the skeleton i have to work with
--------------------------------------
If the customer is an in-state resident, taxRate should be set to .05
If the customer is an out-of-state resident, taxRate should be set to 0.

#include <iostream>
using namespace std;
int main()
{
double taxRate, saleAmount;
char residence;
cout << "Enter the amount of the sale: ";
cin >> saleAmount;
cout << "Enter I for in-state residence or O for out-of-\n";
cout << "state: ";
cin.get(residence);
// Write code here that assigns 0 to taxRate if residence
// is set to 'O' or .05 to taxRate if residence is set
// to 'I'
saleAmount += saleAmount * taxRate;
cout << "The total is " << saleAmount;
return 0;
}


I would really appreciate your help and explanations.
Last edited on
What's the problem? Do you not understand if statements?
http://cplusplus.com/doc/tutorial/control/#if
(residence = O )
This means: set the value of residence to the same as the variable O.

I expect you meant
(residence == 'O' )
which means: test the value of residence for equality to the character 'O'.



Similarly with (residence = I )


It is a bad idea to mix cin >> and cin.get. In this code you can stick to cin >>
Last edited on
Topic archived. No new replies allowed.