468,512 Members | 1,046 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

setprecision

34
Hi, I'm converting codes that I worked with in C to C++ and having a problem with setprecision. At first the code worked, then I made some changes. When the changes didn't work I wrote it back to how it was before and now it's not working. I keep getting the error message where setprecision is undefined. Can anyone help plz.


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. float convertFtoC(int temperature);
  5. int roundUpNextMultiple(int temperature);
  6. int getInput();
  7.  
  8.  
  9. float convertFtoC(int temperature)
  10. {
  11.     float celcius (0.0);
  12.     celcius = (temperature - 32.0) * 5.0/9.0;
  13.     return celcius;
  14. }
  15.  
  16. int foundUpNextMultiple(int temperature)
  17. {
  18.     int addToNextMultiple = temperature % 5;
  19.  
  20.     if(addToNextMultiple != 0)
  21.     {
  22.         addToNextMultiple = 5 - addToNextMultiple;
  23.         temperature = temperature + addToNextMultiple;
  24.     }
  25.     return temperature;
  26. }
  27.  
  28. int getInput()
  29. {
  30.     int input;
  31.  
  32.     cout << "Please enter a temperature greater than 0:\t";
  33.     cin >> input;
  34.  
  35.     while(input <= 0)
  36.     {
  37.         cout << "Error, please re-enter:  ";
  38.         cin >> input;
  39.     }
  40.  
  41.     return input;
  42.  
  43. }
  44.  
  45. int main()
  46. {
  47.     int input = getInput();
  48.     int maxTemp = foundUpNextMultiple(input);
  49.     int start = 0;
  50.     float celcius(0.0); 
  51.  
  52.     cout << "Temperature in F" << "\t" << "Temperature in C\n";
  53.     cout.setf(ios::fixed | ios::showpoint);
  54.     cout.setprecision(2);
  55.  
  56.     while (start <= maxTemp)
  57.     {
  58.         celcius = convertFtoC(start);
  59.         cout << "\t" << start << "\t\t\t" << celcius << "\n";
  60.         start += 5;
  61.     }   
  62. }
Error message occurs at line 54.

Regards,
Jthep
Nov 14 '07 #1
1 4563
jthep
34
Okay, there we go, solved it. I used setprecision vs just cout.precision. Don't know why I used that. I noticed I spelt one of my function calls incorrectly. Wonder why there wasn't an error when compiling.

Regards,
Jthep
Nov 14 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by tarmat | last post: by
2 posts views Thread by Woodster | last post: by
1 post views Thread by Gary Wessle | last post: by
2 posts views Thread by Wing | last post: by
3 posts views Thread by Anjo Gasa | last post: by
7 posts views Thread by jacek.dziedzic | last post: by
2 posts views Thread by mahesh.kanakaraj | last post: by
3 posts views Thread by PengYu.UT | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.