This is my simple temperature conversion program(from F to C). I want to print o
ID: 3770474 • Letter: T
Question
This is my simple temperature conversion program(from F to C).
I want to print out the numbers from 0 up to user input but I'm not sure how.(For example, if the fahr entered by the user was 80, then print value starting from 0 to 80).
I just need a little bit of idea here
#include <iostream>
using namespace std;
void convertFtoC(int, float & );
int main()
{
float cels;
int fahr;
int i;
cout << "Please enter a maximum temperature in Fahrenheit (F)";
cin >> fahr;
while(fahr < 0)
{
cout << "Wrong Input ";
cout << "Select new value: ";
cin >> fahr;
}
cout << "Temperature in F Temperature in C ";
while(fahr <= 300)
{
convertFtoC(fahr, cels);
cout.precision(5);
cout.width(16);
cout << fahr << " " << cels << endl;
fahr = fahr + 5;
}
return 0;
}
void convertFtoC(int f, float &c) {
c = ((f - 32.0) * (5.0/9.0));
}
Explanation / Answer
Highlighted part of the code has been changed
code:
#include <iostream>
using namespace std;
void convertFtoC(int, float * );
int main()
{
float cels;
int fahr;
int i=0;
cout << "Please enter a maximum temperature in Fahrenheit (F)"<<endl<<endl;
cin >> fahr;
while(fahr < 0)
{
cout << "Wrong Input ";
cout << "Select new value: ";
cin >> fahr;
}
cout << " Temperature in F Temperature in C ";
while(i<= fahr)
{
convertFtoC(i, &cels);
cout.precision(5);
cout.width(16);
cout << i << " " << cels << endl;
i++;
}
return 0;
}
void convertFtoC(int f, float *c) {
*c = ((f - 32.0) * (5.0/9.0));
}
output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.