The use of char and string was never explained to me very well and now I've hit a roadblock.
The objective of this program was to give the user options to convert from feet and inches to centimeters or vice versa and to quit when Q is entered.
I know the calculations and such inside the options are functioning correctly but the issue is in getting the program to initiate each option based on user input. I can't tell if the problem is with my initialization or my conditions so I don't know where to start.
#include <iostream>
#include <string>
#include <cmath>
usingnamespace std;
int main ()
{
double ft, cm, in, D;
char F, C, Q;
cout<<"Welcome to the height conversion program!! :)\n"<<endl;
do
{
cout<<"If you're converting from Feet and Inches to Centimeters, input: C\n";
cout<<"If you're converting from Centimeters to Feet and Inches, input: F\n";
cout<<"To quit, input: Q\n";
cin>>D;
if (D=="C")
{
cout<<"Input number of feet: ";
cin>>ft;
cout<<"Input number of inches: ";
cin>>in;
in=in+(ft*12);
cm=in*2.54;
cout<<"The number of centimeters is: "<<cm<<endl;
}
elseif (D=="F")
{
cout<<"Input number of centimeters: ";
cin>>cm;
in=cm/2.54;
ft=in/12;
cout<<"The number of feet and inches is "<<floor(ft)<<"ft "<<fmod(in,12)<<"in\n";
}
}
while (D!="Q");
system ("pause");
return 0;
}
Next in each of your if statements you should be using single quotes around your chars. ( 'C' instead of "C" ) Double quotes creates a c style string which is basically one or more chars followed by null.