Using double in C++

Hello everyone,

Just started programming and am running into some hard times. I am reading my class book and doing video tutorials and searching forums but I have some time sensitive stuff I need to turn in.

I need to get below code to handle fractions of a degree by using the "double" type.

The below is not working! What am I doing wrong ?! Please help.

#include <iostream>
using namespace std;

int main() {
int F;
int C;
double F;
double C;
cout << "I will convert Celsius to Farenheit for you." << endl;
cout << "Enter a Celsius temperature: " ;
cin >> C;
F = C * 9 / 5 + 32;
cout << C << " degrees Celsius is " << F << " degrees Farenheit." << endl;
return 0;
}
1
2
3
4
5
int main() {
int F;
int C;
double F;
double C;


I do not understand why you created two instance of the variable F, C.
The solution to your problem is to delete the int F, int C.
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;

int main() {
double F;
double C;
cout << "I will convert Celsius to Farenheit for you." << endl;
cout << "Enter a Celsius temperature: " ;
cin >> C;
F = C * 9 / 5 + 32;
cout << C << " degrees Celsius is " << F << " degrees Farenheit." << endl;
return 0;
}


In C++ you cannot have two variables with the same name even if the type is different.
Last edited on
Wow thank you I get my mistake now!
Topic archived. No new replies allowed.