+ 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; }

31st Aug 2017, 9:46 AM
Min Khant
Min Khant - avatar
8 odpowiedzi
+ 6
I think your functions are backwards too btw. F_to_C should be C_to_F and vice versa.
31st Aug 2017, 10:00 AM
ChaoticDawg
ChaoticDawg - avatar
+ 5
You also need to add a colon after default. default: // <--- missing colon cout<<"Enter 1 and 2"<<endl;
31st Aug 2017, 9:55 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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);
31st Aug 2017, 9:51 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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; }
31st Aug 2017, 4:25 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
thank you @Chaotic
31st Aug 2017, 9:52 AM
Min Khant
Min Khant - avatar
+ 1
it's ok now Bro, Thank you again...My head gonna explode before u answer this...lol
31st Aug 2017, 9:56 AM
Min Khant
Min Khant - avatar
+ 1
yes bro, I have fixed it
31st Aug 2017, 10:03 AM
Min Khant
Min Khant - avatar
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
31st Aug 2017, 10:13 AM
Min Khant
Min Khant - avatar