String and Char issues

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.

Here's the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <string>
#include <cmath>
using namespace 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;
        }
        else if (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;
}


I would also appreciate any pointers. :)
One issue is the fact that 'D' is a double. It should also be a char.
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.
Oh yeah. I was in the process of experimentation at this point. I had it as a char and then the program would run forever after any input was put in.
AH! Thank you so much! Its running correctly now. I just have to clean up some output stuff and I should be good to go. :D
Topic archived. No new replies allowed.