# what is wrong with this???

• 12-09-2001
Raian
what is wrong with this???
//
// Program to convert temperature from Celsius degree
// units into Fahrenheit degree units:
// Fahrenheit = Celsius * (212-32)/100 +32
//
#include <stdio.h>
#include <iostream.h>

int main(int nNumberofArgs, char* pszArgs[])
{
int exit;
exit = 1;
while (exit==1)
{
int split;
split = 1;
cout << "1. Convert Celsius to Fahrenheit? \n2. Convert Fahrenheit to Celsius?\n"
cin >> split;

// decide which way to convert
if (split == 1)
{

// enter the temerature in Celsius
int celsius;
cout << "Enter the Celsius temprature:\n";
cin >> celsius;

// calculate conversion factor for Celsius
// to Fahrenheit
int factor;
factor = 212 - 32;

// use conversion factor to convert Celsius
// into Fahrenheit values
int fahrenheit;
fahrenheit = factor * celsius/100 + 32;

// output the results
cout << "The Fahrenheit would be:\n";
cout << fahrenheit;
}

else
{

// enter the temerature in Fahrenheit
int fahrenheit;
cout << "Enter the Fahrenheit temprature:\n";
cin >> fahrenheit;

// calculate conversion factor for Fahrenheit
// to Celsius
int factor;
factor = 212 - 32;

// use conversion factor to convert Fahrenheit
// into Celsius values
int celsius;
celsius = factor / fahrenheit * 100 - 32;

// output the results
cout << "The Fahrenheit would be:\n";
cout << fahrenheit;
}

// quit the program or not?
cout << "\nConvert again? \n21. yes \n2. no \n";
cin >> exit;
}

return 0;
}

the compiler says...

18, parse error before `>'

i marked line 18 in bold
• 12-09-2001
SilasP
It looks like you forgot the semicolon in the statement before it.
• 12-09-2001
Raian
oh i c thx
• 12-09-2001
SilasP
• 12-09-2001
Raian
new problem
//
// Program to convert temperature from Celsius degree
// units into Fahrenheit degree units:
// Fahrenheit = Celsius * (212-32)/100 +32
//
#include <stdio.h>
#include <iostream.h>

int main(int nNumberofArgs, char* pszArgs[])
{
int exit;
exit = 1;
while (exit==1)
{
int split;
split = 1;
cout << "1. Convert Celsius to Fahrenheit? \n2. Convert Fahrenheit to Celsius?\n";
cin >> split;

// decide which way to convert
if (split == 1)
{

// enter the temerature in Celsius
int celsius;
cout << "Enter the Celsius temprature:\n";
cin >> celsius;

// calculate conversion factor for Celsius
// to Fahrenheit
int factor;
factor = 180;

// use conversion factor to convert Celsius
// into Fahrenheit values
int fahrenheit;
fahrenheit = factor * celsius/100 + 32;

// output the results
cout << "The Fahrenheit would be:\n";
cout << fahrenheit;
}

else
{

// enter the temerature in Fahrenheit
int fahrenheit;
cout << "Enter the Fahrenheit temprature:\n";
cin >> fahrenheit;

// calculate conversion factor for Fahrenheit
// to Celsius
int factor;
factor = 180;

// use conversion factor to convert Fahrenheit
// into Celsius values
int celsius;
celsius = 180/(100*(fahrenheit-32));

// output the results
cout << "The Celsius would be:\n";
cout << celsius;
}

// quit the program or not?
cout << "\nConvert again?\n1. yes \n2. no \n";
cin >> exit;
}

return 0;
}

okay here is my problem now,,, every time i try to convert fahrenheit to celsius the answer is 0,,, i dont think im dealing with any decimal numbers anywhere... is it just my formula is messed up? its fine on my calculator....
• 12-09-2001
Raian
weeeeeeeeeeeeeee
nm i figured it out now it all works properly and spiffy... btw its my first program that i didnt type out the source from a book, sort of

//
// Program to convert temperature from Celsius degree
// units into Fahrenheit degree units:
// Fahrenheit = Celsius * (212-32)/100 +32
//
#include <stdio.h>
#include <iostream.h>

int main(int nNumberofArgs, char* pszArgs[])
{
int exit;
exit = 1;
while (exit==1)
{
int split;
split = 1;
cout << "1. Convert Celsius to Fahrenheit? \n2. Convert Fahrenheit to Celsius?\n";
cin >> split;

// decide which way to convert
if (split == 1)
{

// enter the temerature in Celsius
int celsius;
cout << "Enter the Celsius temprature:\n";
cin >> celsius;

// calculate conversion factor for Celsius
// to Fahrenheit
int factor;
factor = 180;

// use conversion factor to convert Celsius
// into Fahrenheit values
int fahrenheit;
fahrenheit = factor * celsius/100 + 32;

// output the results
cout << "The Fahrenheit would be:\n";
cout << fahrenheit;
}

else
{

// enter the temerature in Fahrenheit
int fahrenheit;
cout << "Enter the Fahrenheit temprature:\n";
cin >> fahrenheit;

// calculate conversion factor for Fahrenheit
// to Celsius
int factor;
factor = 180;

// use conversion factor to convert Fahrenheit
// into Celsius values
int celsius;
celsius = 100*(fahrenheit-32)/180;

// output the results
cout << "The Celsius would be:\n";
cout << celsius;
}

// quit the program or not?
cout << "\nConvert again?\n1. yes \n2. no \n";
cin >> exit;
}

return 0;
}
• 12-09-2001
SilasP
I think something might be wrong with the formula. You've declared celsius as int type. When you plug in a value into the formula, it's gonna get a little weird. Say you plug in 32 for the fahrenheit degrees, you'll get an error because division by zero is undefined. If you plug in 33 for the degrees, you will get 1.8. If you input 34 degrees, you get 180/200 which is .9 , see what I mean. Check the formula.
• 12-09-2001
Raian
???
so instead of making them int, they should be float?
• 12-09-2001
SilasP
Try double. It covers any that comes out as decimals. If it's declared int, the first whole number is the result. Ex. 0.5 would be 0, or 1.4 would be 1.
• 12-09-2001
Raian
saaa weet ,,, float does the trick i think

//
// Program to convert temperature from Celsius degree
// units into Fahrenheit degree units:
// Fahrenheit = Celsius * (212-32)/100 +32
//
#include <stdio.h>
#include <iostream.h>

int main(int nNumberofArgs, char* pszArgs[])
{
int exit;
exit = 1;
while (exit==1)
{
int split;
split = 1;
cout << "1. Convert Celsius to Fahrenheit? \n2. Convert Fahrenheit to Celsius?\n";
cin >> split;

// decide which way to convert
if (split == 1)
{

// enter the temerature in Celsius
float celsius;
cout << "Enter the Celsius temprature:\n";
cin >> celsius;

// calculate conversion factor for Celsius
// to Fahrenheit
float factor;
factor = 180;

// use conversion factor to convert Celsius
// into Fahrenheit values
float fahrenheit;
fahrenheit = factor * celsius/100 + 32;

// output the results
cout << "The Fahrenheit would be:\n";
cout << fahrenheit;
}

else
{

// enter the temerature in Fahrenheit
float fahrenheit;
cout << "Enter the Fahrenheit temprature:\n";
cin >> fahrenheit;

// calculate conversion factor for Fahrenheit
// to Celsius
float factor;
factor = 180;

// use conversion factor to convert Fahrenheit
// into Celsius values
float celsius;
celsius = 100*(fahrenheit-32)/180;

// output the results
cout << "The Celsius would be:\n";
cout << celsius;
}

// quit the program or not?
cout << "\nConvert again?\n1. yes \n2. no \n";
cin >> exit;
}

return 0;
}
• 12-09-2001
Raian
ok ic double = better