+ 1
What am I wrong? Plz explain this!
#include <iostream> using namespace std; float C_to_F (float a); float F_to_C (float a); int main() { int b; float a,ans; cout<<"Enter Temperature:: "; cin>>a; cout<<"Enter Number to Choose Conversion:: "; cin>>b; switch(b) { case 1: cout<<float C_to_F (float a); break; case 2: cout<<float F_to_C (float a); break; default cout<<"Enter 1 and 2"<<endl; } return 0; } float C_to_F (float a) { return (a-32)*5/9l; } float F_to_C (float a) { return a*(9/5)+32; }
8 Antworten
+ 6
I think your functions are backwards too btw.
F_to_C should be C_to_F and vice versa.
+ 5
You also need to add a colon after default.
default: // <--- missing colon
cout<<"Enter 1 and 2"<<endl;
+ 4
cout<<float C_to_F (float a);
cout<<float F_to_C (float a);
remove float from these 2 lines
cout<< C_to_F (a);
cout<< F_to_C (a);
+ 4
You're using integer/long division, so when you divide 5/9l you will only get the integer part for a result 0, likewise, when you divide 9/5 the result is the integer 1 with no fractional part. You need to declare at least one if not both numbers in the division as type float to get tge proper result of 5/9.0f 0.55556 and 9/5.0f 1.8.
float F_to_C (float a)
{
return (a-32)*5.0f/9.0f;
}
float C_to_F (float a)
{
return a*(9.0f/5.0f)+32;
}
+ 1
thank you @Chaotic
+ 1
it's ok now Bro, Thank you again...My head gonna explode before u answer this...lol
+ 1
yes bro, I have fixed it
0
btw, when I add 1 to Convert C to F, it only output 33. why not float,bro? I ve declared as float type function. i dont know why as I m beginner