Did I write this correctly?

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2008
Posts: 22
Reputation: Foe89 is an unknown quantity at this point 
Solved Threads: 0
Foe89 Foe89 is offline Offline
Newbie Poster

Did I write this correctly?

 
0
  #1
Nov 3rd, 2008
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. void celsius(int);
  6.  
  7. int main()
  8. {
  9. cout << setprecision(2) << fixed << showpoint;
  10. cout << "This program displays a table of the Fahrenheit temperatures"
  11. << "\n0 thorugh 20 and their celsius equivalents.\n";
  12.  
  13. celsius(0);
  14.  
  15. return 0;
  16. }
  17.  
  18. void celsius(int fahr)
  19. { double cels;
  20.  
  21. cout << "Fahrenheit \t \t Celsius\n";
  22.  
  23. for (fahr; fahr <= 20; fahr++)
  24. { cels = (5.0 / 9.0 )*(fahr - 32);
  25. cout << fahr << "\t" << "\t"<< "\t " << cels << endl;
  26. }
  27.  
  28.  
  29. }

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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,056
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 312
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Postaholic

Re: Did I write this correctly?

 
0
  #2
Nov 3rd, 2008
I would first write your function like this :
double celcius(double fahrenheit)
{
//do calculation
return result
}

Now use the function in a for loop to make your table.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 185
Reputation: DemonGal711 is an unknown quantity at this point 
Solved Threads: 10
DemonGal711 DemonGal711 is offline Offline
Junior Poster

Re: Did I write this correctly?

 
0
  #3
Nov 3rd, 2008
Easy, just change your function to
  1. double celsius (int fahr)
  2. { return (5.0 / 9.0)*(fahr - 32); }

And put the call for that inside the for loop you used.
  1. // Top of table
  2. for (int fahr = 0; fahr <= 20; fahr++)
  3. { double cels = celsius (fahr);
  4. /* Display individual data for table */}
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 404 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC