ISO C++ Forbids comparison between pointer...

October 18, 2011 at 15:25:07
Specs: Windows Vista
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
int weight;
char planet;
string letter;
float cw;

cout << "Enter your weight in pounds: ";
cin >> weight;

cout << "Planets: Mercury, Venus, Earth, mOon, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto" << endl;
cout << "Enter the planet initial: ";
cin >> planet;

if (planet == "Earth")
cw = weight;

else if (planet == "Moon")
cw = weight * 0.166;

else if (planet == "Mercury")
cw = weight * 0.4155;

else if (planet == "Venus")
cw = weight * 0.8975;

else if (planet == "Mars")
cw = weight * 0.3507;

else if (planet == "Jupiter")
cw = weight * 2.5374;

else if (planet == "Saturn")
cw = weight * 1.0677;

else if (planet == "Uranus")
cw = weight * 0.8947;

else if (planet == "Neptune")
cw = weight * 1.1794;

else if (planet == "Pluto")
cw = weight * 0.0899;

cout << fixed << setprecision(0) << "Your weight on " << planet << " is: " << cw << " lbs" << endl;

switch (planet){

case 'M' : cw = 0.4155 * weight;
break;

case 'V' : cw = 0.8975 * weight;
break;

case 'E' : cw = weight;
break;

case 'O' : cw = 0.166 * weight;
break;

case 'M' : cw = 0.3507 * weight;
break;

case 'J' : cw = 2.5374 * weight;
break;

case 'S' : cw = 1.0677 * weight;
break;

case 'U' : cw = 0.8947 * weight;
break;

case 'N' : cw = 1.1794 * weight;
break;

case 'P' : cw = 0.0899 * weight;
break;
}
}


now this program is supposed to calculate your weight on other planets, the IF statement works, but the switch statement doesn't


See More: ISO C++ Forbids comparison between pointer...

Report •


#1
October 19, 2011 at 00:03:48
You can't use the == operator with normal C strings.

Report •
Related Solutions


Ask Question