Hi Guys
Im trying to wirte a program that reads in 10 tempruratures then sends them
to a function which converts them to farhenheit. It compiles ok but its only converting and returning the first value as the output.
I guess I am making a very obvious mistake but cannot see where.
here is my code I appreciate any help on this:
Code:#include <iostream> #include <iomanip> // function prototype double celsius ( double[], const int ); // main function - begins program execution //////////////////////////////////// // int main ( void ) { const int ARRAY_SIZE = 10; double cel[ ARRAY_SIZE ] = { 0 }; std::cout << "Enter 10 temp in celsius: "; for ( int i = 0; i < ARRAY_SIZE; i++ ) { std::cin >> cel[ i ]; } std::cout << "\nCELSIUS" << std::setw( 17 ) << "FARHENHEIT\n\n"; for ( int i = 0; i < ARRAY_SIZE; i++ ) { std::cout << cel[ i ] <<std::setw( 17 ) << celsius ( cel, ARRAY_SIZE ) << std::endl; } std::cin.get(); // freeze console output window std::cin.ignore(); return 0; // return value from int main } double celsius ( double x[], const int size ) { double farhenheit; for ( int k = 0; k < size; k++ ) { // calculate conversion from celsius // to farhenheit int factor = 212 - 32; // convert celsius to farhenheit farhenheit = factor * x[ k ] / 100 + 32; } return farhenheit; }



LinkBack URL
About LinkBacks



CornedBee