lundi 27 février 2017

If statement not reading char variable properly

When calling the programs starLeftTriangle & starRightTriangle, the if statements seem to ignore the variable choice and the program continuously runs as if the choice is 'l' or 'L'.

Any idea why the if statements are being ignored? I've omitted the actual code for the programs.

#include <iostream>
using namespace std;

void starLeftTriangle(int n);
void starRightTriangle(int n);


int main() {
int star;
char choice;
cout << "Input the number of stars you want to draw: \n";
cin >> star;
cout << "Would you like to draw a left triangle, right triangle, or quit?     \n";
cin >> choice;

cout << "The choice value is " << choice << endl;

system("pause");

while (choice != 'q' || 'Q'){
    if (choice == 'l' || 'L'){
        starLeftTriangle(star);
    }
    else if (choice == 'r' || 'R') {
        starRightTriangle(star);
    }
}
if (choice == 'q' || 'Q') {
    cout << "Quitting Program.";

}
else{
//throw error
}
return 0;

}

Aucun commentaire:

Enregistrer un commentaire