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()

    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

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...

8 Years
Discussion Span
Last Post by ShawnCplus

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.

Votes + Comments

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.