Ok, new to C++, I bet this is a real easy question.

Every time I input a char, it enters the same char twice to variable. So when I enter "r", and then output it..it outputs "rr"

#include <iostream>
#include <fstream>
using namespace std;

#define errorMsg1       "You must enter 'F' for Fahrenheit or 'C' for Celsius."
#define enterDegreeType "Would you like to convert......\n"

char degreeType;


int main()
{
    //clrscr();
   
    cout<<enterDegreeType;
    cin>>degreeType;

    if (degreeType != 'c' || degreeType !='f')
    {
        cout <<"\n"<<errorMsg1;
        cout <<"You entered "<<degreeType;
    }
    cout <<degreeType;
    return 0;
}

This is what I get.......
"Would you like to convert a Fahrenheit degree or a Celsius degree?
Type 'F' for Fahrenheit or 'C' for Celsius
c

You must enter 'F' for Fahrenheit or 'C' for Celsius.You entered cc
Process returned 0 (0x0) execution time : 1.846 s
Press any key to continue."


Program is clearly not done. I'm just trying to get it to input and check it correctly...

if (degreeType != 'c' || degreeType !='f')

How can degreeType be both 'c' and 'f' at the same time? It can't obviously, so the above statement will always resolve to true. Therefore, you always get the error message followed by the output of degreeType on line 23 followed by the output of degreeType on line 25, without a new line or space char between the two outputs.

commented: helpful +2

Thank you. I was so focused on input that I didn't see the obvious. Thanks again.

It's also not doubling in the variable, you're just outputing the variable twice. You have a cout inside the if, and a cout before the return.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.