Whats wrong?

I need to calculate and make a table with temperature conversions from farenheit
to celsius and kelvin. Here's what I have so far...

#include <cstdlib>
#include <iostream>
#include <cmath>
#include <iomanip>


using namespace std;

int main(int argc, char *argv[])
{ //Ask user to input information
double int_temp, end_temp, step_temp, farenheit, celsius, kelvin;
int prcse_unit;
char ans;
cout<<"This program makes a temperature conversion table from Farenheit"<<endl<<endl;
do
{
bool repeat;
do
{
cout<<"What is the intial temperature in Farenheit? ";
cin>>int_temp;
if(repeat = int_temp <= 0)
cout<<"Cannot compute with a zero or negative initial temperature. Please re-enter"<<endl;
}while(repeat);
do
{
cout<<"What is the ending temperature in Farhenheit? ";
cin>>end_temp;
if(repeat = end_temp <= int_temp)
cout<<"Cannot compute with a temperature greater than the initial temperature. Please re-enter"<<endl;
}while(repeat);
do
{
cout<<"What is the step size between temperatures? ";
cin>>step_temp;
if(repeat = step_temp <= 0)
cout<<"Cannot compute with a zero or negative step size in temperature. Please re-enter"<<endl;
}while(repeat);
do
{
cout<<"How many units of precision do you want?";
cin>>prcse_unit;
if(repeat=prcse_unit<=0)
cout<<"Cannot have a negative precision value. Please re-enter"<<endl;
}while(repeat);

//Calculate and print conversion table
cout<<endl<<endl<<endl<<"Conversion Table"<<endl<<endl;
cout<<"-------------------------------------------------------------------------------";
cout<< setw(15) << "Farenheit"<< setw(15) << "Celsius" << setw(15) << "Kelvin" <<endl;
for(farenheit=int_temp;farenheit<=end_temp;farenheit=int_temp+step_temp)
{
celsius= (farenheit-32)/1.8;
kelvin= celsius+273.15;
cout<< setw(15)<< farenheit << setw(15)<< celsius<< setw(15)<< kelvin<< endl;

}

cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"Would you like to do this again?";
cin>>ans;
}while(ans == 'Y' || ans == 'y');
system("PAUSE");
return EXIT_SUCCESS;
}

it runs but messes up any ideas?
Last edited on
closed account (D80DSL3A)
How is it messing up?

I see a problem with the for loop:
for(farenheit=int_temp;farenheit<=end_temp;farenheit=int_temp+step_temp)

I think you want to increment farenheit by step_temp each iteration here. This may work better:
for(farenheit=int_temp;farenheit<=end_temp;farenheit+=step_temp)
well previously it would never end calculating, like when i would input 10-20 degree it kept going at 12

but thank it's stopping now
Topic archived. No new replies allowed.