0

hi, I was hoping someone could help me. I've been trying to do this for the past hour with no luck.

basically i'm trying to make a Celcius to Fahrenheit converter. So far, the converter works fine, except for the fact that I cant get it to display 2 decimal places when I get the conversion answer...

I've tried looking around everywhere on multiple sites and guides for precision setting, but they dont work...

what am I doing wrong? Please help...

// mytemp.cpp

#include <iostream>
using namespace std;

int main ()
{
  int c;
  cout << "Celcius: ";

  cin >> c;

  cout.setf(ios::fixed);
  cout << "Fahrenheit: " << ((c*9)/5)+32 << '\n';

  return 0;

}
2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
0

setprecision(2)

#include <iostream>
#include <iomanip>
using namespace std;


int main ()
{
  int c;
  cout << "Celcius: ";

  cin >> c;

  cout.setf(ios::fixed);
  cout << "Fahrenheit: " << setprecision(2) << (((float)c*9.0)/5.0)+32.0 << '\n';

  return 0;

}
0

wow, thanks Ancient Dragon. that works great! i guess I missed the "float". I used just the setprecision but it didnt work

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.