I am having trouble writing this program for temperatureconversion. I have writt
ID: 3615820 • Letter: I
Question
I am having trouble writing this program for temperatureconversion. I have written down the problem and what I have so far.Any help will be greatly appreciated.
Write a program that allows the user to enter 5 Fahrenheittemperatures and converts these 5 temperatures to Celsiustemperatures. Output a table of the Fahrenheit and Celsiustemperatures. Include headings for the table. Use onearray to store the Fahrenheit temperatures and another array tostore the Celsius temperatures.
#include <iostream>
#include <cmath>
using namespace std;
double
convert(double celsius){
double fahrenheit = ((9.0/5.0) * celsius) + 32;
return fahrenheit;
};
int main()
{
int counter = 0;
int flag = 1;
int myarray[5];
while(flag==1&&counter<50)
{
cout << "Enter Temperature Reading:";
cin>>myarray[counter];
counter++;
cout << " Enter 1 to input more values, 0 tostop";
cin >>flag;
}
return 0;
system ("pause");
}
Explanation / Answer
I haven't done any C or C++ programming, but I can still understandyour code. So I can point out a few things. See, you never actually use your convert method. When you dothough, remember to make a separate array to store the values ofthe other temperature. Then, simply use a for loop to go across allthe positions in the array to load the values. Here is somepseudo-code: public double convert(double f) { return 5.0/9.0*(F-32.0); } double[] f = new double[5]; // create a new array for the fahrenheittemperatures Scanner scan = new Scanner(System.in); System.out.println("Please Enter 5 FahrenheitTemperatures: "); for(int i = 0; i < 5; i++) { f[i] = scan.nextDouble(); } double[] c = new double[5]; for(int i = 0; i < 5; i++) { c[i] = convert(f[i]); }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.