question archive This is C++ 1 ) Create a array of Fahrenheit temperatures, as follows int fahr []= {0,1,2,3,4,5,6,7,8,9,10,32,33,34,35,36,37,38,39,40}; 2) Create a function convertFarh(int fahr) that converts Fahr to Celsius, a function such as you did in class, outside of main(), above it
Subject:Computer SciencePrice:4.86 Bought8
This is C++
1 ) Create a array of Fahrenheit temperatures, as follows
int fahr []= {0,1,2,3,4,5,6,7,8,9,10,32,33,34,35,36,37,38,39,40};
2) Create a function convertFarh(int fahr) that converts Fahr to Celsius, a function such as you did in class, outside of main(), above it.
3) Create a loop inside main() function, that prints side by side Fahrenheit temperatures from the array above (in a similar way how you printed an array in class) and Celsius temperature by calling function convert(...) in the loop to get a matching Celsius temperature for each Fahrenheit temperature that you print.
Code:
#include <iostream> #include <iomanip> using namespace std; float converFarh(int Farh) { float celcius = 0; celcius = float((float(Farh) - 32) * 5 / 9); return celcius; } int main() { int fahr[] = { 0,1,2,3,4,5,6,7,8,9,10,32,33,34,35,36,37,38,39,40 }; int size = (sizeof(fahr) / sizeof(fahr[0])); cout << left << setw(25) << "Fahrenheit Temperatures" << right << setw(25) << "Celsius Temperatures" << endl; for (int i = 0; i < size; i++) { cout << left << setw(25) << fahr[i] << right << setw(25) <<setprecision(4)<< converFarh(fahr[i]) << endl; } }
Output:
Please see the attached file for the complete solution