Hello,
I am new to C++ and have been working through a bunch of problems for school. Im really stuck on a homework and Im hoping to get some guidance on what I should be doing.
The problem is converting celsius to Fahrenheit. I have created a loop and table and think I have my formulas worked out pretty well. However im really stuck on what to do with some added problems.
I need to have the user enter a start a stop temperature in Celsius which sets the parameters of the table. I think I got that part figured out, but this is where my trouble begins.
no matter which order the start and stop temperatures are entered, the lowest needs to be the start.
also negative numbers can be entered and the start temperature needs to round down to the nearest integer while the stop temperature needs to round up to the nearest integer.
I have tried a bunch of different stuff to figure this out but haven't had any luck. Any helpful advice would be greatly appreciated.
I was thinking of adding something like this for the order part
if (start > Stop) {
cout << Stop;
else
cout << Start;
and something like this for the rounding part
int = (int)(start + 0.5);
int = (int)(stop - 0.5);
Here is the code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main () {
double C = 0;
double Start;
double Stop;
double F;
cout << fixed << showpoint;
cout << endl;
cout << "Enter Start Temp ";
cin >> Start;
cout << endl;
cout << "Enter Stop Temperture";
cin >> Stop;
cout << endl;
//Calulate
if (Start < Stop){
cout << Start;}
else {
cout << Stop;
}
cout << F << endl;
const int COL1 = 12;
const int COL2 = 12;
cout << right;
cout << setprecision(2);
cout << endl;
cout << setw(COL1 + COL2) << "Celsius to Fahrenheit Table" << endl;
cout << endl;
cout << setw(COL1) << "Celsuis" << setw(COL2) << "Fahrenheit" << endl;
cout << endl;
int table = 1;
while (table <= COL1 + COL2){
cout << "=" ;
table++;
}
cout << endl;
for (C = Start; C <= Stop; C++) {
F = ((9.0 / 5.0) * C ) + 32;
cout << setw(COL1) << C << setw(COL2) << F << endl;
}
cout << endl;
return 0;
}
|