Hello!

I'm trying to make a command line program that converts Celsius to Fahrenheit, and then asks if you would like to convert another number. This is the code I have (below) however when it gets to the point of asking if you would like to convert another number, no matter the input it always exits! Please advise!

#include <stdio.h>
#include <iostream>

using namespace std;
int main(int nNumberofArgs, char * pszArgs[])
{
	for(;;)
	{
	// enter the temperature in celsius
	int nCelsius;
	cout << "Enter the temperature in Celsius:";
	cin >> nCelsius;

	//Conversion factor for celsius to fahrenheit
	int nFactor;
	nFactor = 212 - 32;
	int nFahrenheit;
	nFahrenheit = nFactor * nCelsius/100 + 32;
	//output the results
	cout << "Fahrenheit value is:";
	cout << nFahrenheit;
	//loop?
	cout << "Would you like to preform another conversion? Enter Y for yes or N for no";
	
	char cDoContinue;
	cin >> cDoContinue;

	if(cDoContinue = 'n'){
		break;
	}
	system("PAUSE");

	}
	return 0;
}

PS. If you can also find a way to format the text so there are breaks between each "cout" that would be great!

Thanks!

You're equating, not comparing..

if(cDoContinue = 'n'){

should be

if(cDoContinue == 'n'){

better yet

if( tolower(cDoContinue) == 'n'){

Edited 3 Years Ago by mike_2000_17: Fixed formatting

You're equating, not comparing..

if(cDoContinue = 'n'){
should be
if(cDoContinue == 'n'){
better yet
if( tolower(cDoContinue) == 'n'){

Thanks! It works great!

However what is the difference between

if( tolower(cDoContinue) == 'n'){

and

if(cDoContinue == 'n'){

Forced lower case.

If the user entered 'N' meaning no then it would be treated like yes!
Since it isn't a 'n'. But using a tolower( ch ) forces the (ch) to lower case!

This question has already been answered. Start a new discussion instead.