Ok. i am trying to write andd if else statement , so that a user can choose if he wants to convert celcius to farenhiet (spelling?) or the other way around. I can only get the conversion to go one way, i cannot get the else statment to recognized. could some one please explain to me why no matter what i put in it will always do the if statement? here is my code
Code:#include <iostream> using namespace std; float convert(float); float convert2(float); int main() { float tempfar; float tempcel; char f = 1; char c = 2; char answer; cout<<"would you like convert to Farenhiet(1) or to celcius(2)? "; cin>>answer; cin.ignore(); if (answer > 1) { cout<<"Please enter the temp in Farenhiet: \n"; cin>>tempfar; cin.ignore(); tempcel = convert(tempfar); cout<<"The temp converted to celcius is : "; cout<< tempcel << endl; } else cout<<"Please enter the temp in celcius: \n"; cin>>tempcel; cin.ignore(); tempfar = convert2(tempcel); cout<<"Here is youre answer in farenheit: "; cout<< tempfar << endl; cin.get(); } float convert (float far) { float cel; cel = ((far - 32) * 5) / 9; return cel; } float convert2 (float cel) { float far; far=((cel*9) / 9) + 32; return far; }
any help will be appreciated and any tips on coding also i have only been coding for about 3 days