472,993 Members | 2,313 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 software developers and data experts.


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;
  4. float convertFtoC(int temperature);
  5. int roundUpNextMultiple(int temperature);
  6. int getInput();
  9. float convertFtoC(int temperature)
  10. {
  11.     float celcius (0.0);
  12.     celcius = (temperature - 32.0) * 5.0/9.0;
  13.     return celcius;
  14. }
  16. int foundUpNextMultiple(int temperature)
  17. {
  18.     int addToNextMultiple = temperature % 5;
  20.     if(addToNextMultiple != 0)
  21.     {
  22.         addToNextMultiple = 5 - addToNextMultiple;
  23.         temperature = temperature + addToNextMultiple;
  24.     }
  25.     return temperature;
  26. }
  28. int getInput()
  29. {
  30.     int input;
  32.     cout << "Please enter a temperature greater than 0:\t";
  33.     cin >> input;
  35.     while(input <= 0)
  36.     {
  37.         cout << "Error, please re-enter:  ";
  38.         cin >> input;
  39.     }
  41.     return input;
  43. }
  45. int main()
  46. {
  47.     int input = getInput();
  48.     int maxTemp = foundUpNextMultiple(input);
  49.     int start = 0;
  50.     float celcius(0.0); 
  52.     cout << "Temperature in F" << "\t" << "Temperature in C\n";
  53.     cout.setf(ios::fixed | ios::showpoint);
  54.     cout.setprecision(2);
  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.

Nov 14 '07 #1
1 4817
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.

Nov 14 '07 #2

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

Similar topics

by: tarmat | last post by:
I'm trying to create a function that will turn a float into a std::string that always shows the number to two decimal places. I have the following but it doesn't give the desired output: ...
by: Woodster | last post by:
I am using the std::setprecision function to format variables of type double in a string however I am unsure how to stop this appearing in scientific notation. For example std::stringstream...
by: Gary Wessle | last post by:
hi the code below is giving me what I want but it is very ugly. and will not work for a long list of different length numbers. could you please look at it and comment. thank you the...
by: Wing | last post by:
Hello everyone, I have the following code: /////////////////////////////////////// double num; num=1234567890; num+=(1.0/3.0); cout.setf(ios::fixed);
by: Anjo Gasa | last post by:
I'm having some cases where setprecision in combination with iostreams gives some unepected behavior. Consider the following program: #include <iostream> #include <iomanip> int _tmain(int...
by: jacek.dziedzic | last post by:
Hello! Can someone tell me what the expected output of the following program is? #include <fstream> #include <iomanip> using namespace std;
by: mahesh.kanakaraj | last post by:
Hi All, I am new to C++ programming. I encounter an unexpected behavior of 'setprecision'. The code snippet is : #include <iostream.h> #include <stdio.h> #include <iomanip.h>
by: PengYu.UT | last post by:
Hi, I setprecision to be 100 for both cases. I'm wondering why the number of digits are different. Also, for a double number, I think any digits that are longer than 15 (or 16) are not...
by: victoryusami | last post by:
I'm not 100% sure whats even going on, but I'm working on a C++ assignment for school, and its a road trip program #include <iostream> #include <iomanip> using namespace std; char const...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.