I just reconstructed my new code and am having trouble. When I try to compile it I keep getting an error message. At the end of the program something is wrong, but I can't figure it out.

#include <iostream>
#include <cmath> 
#include <string>

using namespace std;

int main ()
{
	int weight;
	string Planet;
	char signal; //for when the program is prompted to terminate	
	
	
	{
		do {
			cout << "Please enter a weight between 0 to 1000 pounds rounded to the nearest whole number" << endl; //Prompts user to input valid weight
			cin >> weight;
			if (weight >= 0 && weight <= 1000) //Uses the condition that the weights have to be between 0 and 1000 to continue
				
			{
				cout << "Please enter a planet name from the following list." << endl;
				cout << "Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune" << endl;
				
				cout.precision(2)
				if(Planet== "Mercury"){
					cout << "The weight on Mercury is " << (weight*0.4155)<< endl;
				}
				else if(Planet== "Venus"){
					cout << "The weight on Venus is " << (weight*0.8975)<< endl;
				}
				else if(Planet== "Earth"){
					cout << "The weight on Earth is " << (weight*1.0)<< endl;
				}
				else if(Planet== "Mars"){
					cout << "The weight on Mars is " << (weight*0.3507)<< endl;
				}
				else if(Planet== "Jupiter"){
					cout << "The weight on Jupiter is " << (weight*2.5374)<< endl;
				}
				else if(Planet== "Saturn"){
					cout << "The weight on Saturn is " << (weight*1.0677)<< endl;
				}
				else if(Planet== "Uranus"){
					cout << "The weight on Uranus is " << (weight*0.8947)<< endl;
				}
				else if(Planet== "Neptune"){
					cout << "The weight on Neptune is " << (weight*1.1794)<< endl;
								
				else
				{
					cout << "Press c to input a new weight or q to terminate the program" << endl; //terminate or continue prompt
					cin >> signal;
				}
				
			}
			else if (weight <= 0 || weight >= 1000) //When user has not input a valid weight
				cout << "Please enter in a weight between 0 and 1000" << endl;
		} while (signal != 'q'); //Keeps repeating the program process until user inputs correct data until user presses 'q'
			
	}		
	if (signal = 'q') // When q is pressed the program terminates
		cout << "The program has ended, Have a nice day." << endl;
	
	return 0;
}

You have forgotten to add a curly brace at the end of:

else if(Planet== "Neptune"){	
cout << "The weight on Neptune is " << (weight*1.1794)<< endl;

It should read

else if(Planet== "Neptune"){	
cout << "The weight on Neptune is " << (weight*1.1794)<< endl;
}

ok just guesses but
line 14 why?
do while signal !='q'
initially what value does signal have?

Edited 5 Years Ago by frogboy77: n/a

why have the line at all? when the program reaches this point and breaks the do while loop then surely signal does equal q.

Edited 5 Years Ago by frogboy77: n/a

Also Planet is never assigned to...

And in line 24

cout.precision(2)

doesn't that need a semi-colon:

cout.precision(2);

Same argument as frogboy77 for line 56:

else if (weight <= 0 || weight >= 1000)

Surely if you're at this point the the weight isn't between 0 and 1000 and so why bother doing a check for it?

ok this is what I have now. When I run the code the first step works fine and the second step also. The problem occurs when I enter in the planet name. Instead of outputting the value, it continuously repeats:

"Please enter a planet name from the following list.
Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune
Press c to input a new weight or q to terminate the program"

Instead of outputting the value. What am I doing wrong?

#include <iostream>
#include <cmath> 
#include <string>

using namespace std;

int main ()
{
	int weight;
	string Planet;
	char signal; //for when the program is prompted to terminate	
	
	
	{
		do {
			cout << "Please enter a weight between 0 to 1000 pounds rounded to the nearest whole number" << endl; //Prompts user to input valid weight
			cin >> weight;
			if (weight >= 0 && weight <= 1000) //Uses the condition that the weights have to be between 0 and 1000 to continue
				
			{
				cout << "Please enter a planet name from the following list." << endl;
				cout << "Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune" << endl;
				
				cout.precision (2);
				if(Planet== "Mercury"){
					cout << "The weight on Mercury is " << (weight*0.4155)<< endl;
				}
			    else if(Planet== "Venus"){
					cout << "The weight on Venus is " << (weight*0.8975)<< endl;
				}
				else if(Planet== "Earth"){
					cout << "The weight on Earth is " << (weight*1.0)<< endl;
				}
				else if(Planet== "Mars"){
					cout << "The weight on Mars is " << (weight*0.3507)<< endl;
				}
				else if(Planet== "Jupiter"){
					cout << "The weight on Jupiter is " << (weight*2.5374)<< endl;
				}
				else if(Planet== "Saturn"){
					cout << "The weight on Saturn is " << (weight*1.0677)<< endl;
				}
				else if(Planet== "Uranus"){
					cout << "The weight on Uranus is " << (weight*0.8947)<< endl;
				}
				else if(Planet== "Neptune"){
					cout << "The weight on Neptune is " << (weight*1.1794)<< endl;
				}	
					
				{
					cout << "Press c to input a new weight or q to terminate the program" << endl; //terminate or continue prompt
					cin >> signal;
				}
				
			}
			else if (weight <= 0 || weight >= 1000) //When user has not input a valid weight
				cout << "Please enter in a weight between 0 and 1000" << endl;
		} while (signal != 'q'); //Keeps repeating the program process until user inputs correct data until user presses 'q'
			
	}		
	if (signal == 'q') // When q is pressed the program terminates
		cout << "The program has ended, Have a nice day." << endl;
	
	return 0;

after line 22, you need to be reading in a value into Planet, at the moment it does nothing and so planet is "".

How would I go about doing that?? and I'm still getting the same problem when I try to type in a planet name, it just keeps repeating over and over and over.

I'm becoming very depressed. This is so complicated.

where is the user telling you which planet they are on?

you ask a question:

cout << "Please enter a planet name from the following list." << endl;
				cout << "Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune" << endl;

but you don't ask for an answer.

Edited 5 Years Ago by frogboy77: n/a

where is the user telling you which planet they are on?

you ask a question:

cout << "Please enter a planet name from the following list." << endl;
				cout << "Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune" << endl;

but you don't ask for an answer.

My eyes must be hallucinating. Thanks. I have to finish this by tonight, I'll correct this problem now.

Thanks once again.

Hopefully I can finally finish this program.

This article has been dead for over six months. Start a new discussion instead.