I'm trying to make my program output what your weight would be on a plant or the moon depending on what letter the user inputs. So far it's not working, if i use int values it works fine but as soon as i try using char values it won't work.I really need help on this.
heres the program
#include <iostream> //Header
#include <string>
//Constants
const double e = 0.8975; //Venus coefficient
const double a = 1.0; //Earth coefficient
const double o = 0.166; //Moon coefficient
const double u = 2.5374; //Jupiter coefficient
const double t = 1.0677; //Saturn coefficient
cout << "please enter your weight" << endl << endl;
cin >> weight;
cout << "Now please enter one of the numbers that corresponds" << endl;
cout << "to one of the following plants or moon:" <<endl << endl;
cout << "Venus=1, Earth=2, Moon=3, Jupiter=4, Saturn=5."<<endl << endl;
cin >> plantLet;
else
{
if (plantLet!= V && E && M && J && S)
cout << "Error: Number entered was incorrect; please input one of the following numbers, " << endl;
cout << "1, 2, 3, 4, 5." << endl;
}
This is comparing your variable plantLet to a variable named V. You never gave V a value, so this is meaningless. Just because you named the variable V does not mean it represents the character V. You could just as easily name it WorchestershireSauce -- the names of variables do not matter.
If you want to compare against the actual letter 'V', then you need to use a character literal, not a variable. Do this by putting the character inside single quotes:
1 2 3
// char V; // <- get rid of all of these
if(plantLet == 'V') // use 'V', not V. Also I don't know why you had <=
Also:
if (plantLet!= V && E && M && J && S)
This code does not do what you expect. There is no need for it anyway, since the 'else' chain ensures that plantLet is not any one of the previously checked options.
That did not work, I changed the if (plantLet == "V") and got rid of the char V; stuff but the == not has an error that says "operand types are incompatible (char and const char)"
A suggestion: Use the toupper function on your "if" statements. Input is case-sensitive, and users are more likely to use lower-case input than upper-case. That will help avoid bad data.
Oh, incidentally, your instructions and your programming logic don't really match, since if the user enters a one, it'll drop down to your "else." You might want to revise them to say:
1 2
cout << "Now please enter one of the following:" << endl << endl;
cout << "(V)enus, (E)arth, (M)oon, (J)upiter, (S)aturn"<< endl << endl;