| | |
Did I write this correctly?
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 22
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <iomanip> using namespace std; void celsius(int); int main() { cout << setprecision(2) << fixed << showpoint; cout << "This program displays a table of the Fahrenheit temperatures" << "\n0 thorugh 20 and their celsius equivalents.\n"; celsius(0); return 0; } void celsius(int fahr) { double cels; cout << "Fahrenheit \t \t Celsius\n"; for (fahr; fahr <= 20; fahr++) { cels = (5.0 / 9.0 )*(fahr - 32); cout << fahr << "\t" << "\t"<< "\t " << cels << endl; } }
The question is
"Write a function named celsius that accepts a Fahrenheir temperature as an argument. The function should return the temperature, converted to celsius. Demonstrate the function by calling a loop that displays a table of the Fahrenheit temperatures 0 through 20 and their celsius equivelents."
It sounds like to me that I just need the function to form the celsius degree, and that it should be displayed in the main function and not the void function like I have it above.
•
•
Join Date: Apr 2008
Posts: 185
Reputation:
Solved Threads: 10
Easy, just change your function to
And put the call for that inside the for loop you used.
C++ Syntax (Toggle Plain Text)
double celsius (int fahr) { return (5.0 / 9.0)*(fahr - 32); }
And put the call for that inside the for loop you used.
C++ Syntax (Toggle Plain Text)
// Top of table for (int fahr = 0; fahr <= 20; fahr++) { double cels = celsius (fahr); /* Display individual data for table */}
![]() |
Similar Threads
- Some issues with #define "string" and the write function (unix socket related). (C)
- Did I do the windchill index correctly.Due in 18hrs.Is there other ways to write this (Python)
- Did I write this correctly, and is there other way to writ it? (Python)
- Winsnm Programming (C++)
- Exercise using: unsigned char bcd(int n); (C)
- padobot.v (Viruses, Spyware and other Nasties)
- I need to re-write this code using a 'while' loop. (Java)
Other Threads in the C++ Forum
Views: 404 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






