I have been going over and over this, and for the life of me I can't figure out what I'm doing wrong. All this is supposed to do is take a number and a letter, determine weather to use celsius or fahrenheit conversion (or neither) then run the conversion five times. this is the code:
If you enter c or C, it goes through the celsius conversion twice, (first five times, then six), fahrenheit once (six times), then the error message. And it increments all the way through, so if I start with 32, the last temperature it converts in fahrenheit is 49. If I enter fahrenheit or the default it does similar (and similarly frustrating) things.Code:#include <iostream> #include <iomanip> using namespace std; float getinfo (float&, char&); float selscale (char&,int&,float&,float,float); float celscl (int, float&, float); float calccel ( float&,float); float fahscl(int, float&, float); float calcfah (float&, float); void CnorF(); int main () { char scl; float deg; int count; float degC; float degF; getinfo (deg, scl); selscale (scl,count,deg,degF,degC); celscl (count,deg,degF); calccel ( deg, degF); fahscl(count, deg,degC); calcfah (deg, degC); CnorF(); system ("pause"); return 0; } float getinfo (float& deg, char& scl) { cout<<"Please enter the temperature followed by C or F (celsius or fahrenheit):" <<endl; cin>>deg; //temperature cin>>scl; //scale (celsius or fahrenheit) } float selscale (char& scl,int& count,float& deg,float degF, float degC) { if (scl == 'c'|| scl == 'C') //goes to celsius { celscl(count,deg,degF); calccel (deg,degF); } else if(scl == 'f'|| scl == 'F') //goes to fahrenheit { fahscl(count,deg,degC); calcfah (deg,degC); } else { CnorF (); //goes to error message } } float celscl (int count,float& deg,float degF) { cout<<"celsius to fahrenheit conversion"<<endl; cout<<setw(8)<<"celsius"<<setw(38)<<"fahrenheit"<<endl; cout<<setw(8)<<"-------"<<setw(38)<<"----------"<<endl; cout<<fixed<<showpoint<<setprecision(2); for (count=1;count<=5;count++) //runs calccel 5 times { calccel (deg, degF); } } float calccel ( float& deg,float degF) //.celcius to fahrenheit { degF = ((9.0/5.0)*deg) + 32; cout<<setw(7)<<deg; cout<<setw(36)<<degF<<endl; deg++; } float fahscl (int count, float& deg,float degC) { cout<<"fahrenheit to celsius conversion"<<endl; cout<<"fahrenheit"<<setw(34)<<"celsius"<<endl; cout<<"----------"<<setw(34)<<"-------"<<endl; cout<<fixed<<showpoint<<setprecision(2); for (count=1;count<=5;count++) //runs calcfah 5 times { calcfah (deg, degC); } } float calcfah (float& deg, float degC) //converts fahrenheit to celsius { degC = (5.0/9.0)*(deg-32); cout<<setw(7)<<deg; cout<<setw(36)<<degC<<endl; deg++; } void CnorF() { cout<<"The letter you entered was not C or F, please try again."<<endl; return; //error message }
Is there something obvious that I'm missing? As you might have noticed, I'm new at this. I've hacked this thing into bits and pieces but have yet to find out where the problem is.



LinkBack URL
About LinkBacks


