Hello, I have created 2 if statements, the second statement is correct but the first statement seems to get skipped, can you please help? Thank you. As a side note I'm also attempting to determine how many white spaces there are if you press space after typing in a letter.
#include<iostream>
#include<cctype>
using namespace std;
int main()
{
int counter = 1; // Counter for do loop
do
{
char c;
char yesNo = 'N';
cout << "Please enter a letter";
cin >> c;
// Create if statements that decides if the letter
// enetered is either uppercase or lower case.
if (c >= 'a' && c <= 'z')
{
c = toupper(c);
}
if (c >= 'A' && c <= 'Z')
{
c = tolower(c);
}
cout << "The output is: " << c;
// Prompting user that letter was not entered and digits was
// entered instead.
if (c = isdigit(c))
{
cout << "You entered number, would you like to try again? Y/N.";
cin >> yesNo;
}
if (yesNo == 'Y' || yesNo == 'y')
{
counter += 1;
}
if (yesNo == 'N' || yesNo == 'n')
{
counter -= 1;
}
cout << "Please enter Y/N to try again";
cin >> yesNo;
if (yesNo == 'Y' || yesNo == 'y')
{
counter += 1;
}
if (yesNo == 'N' || yesNo == 'n')
{
counter -= 1;
}
if (c >= 'a' && c <= 'z')
{
c = toupper(c);
}
if (c >= 'A' && c <= 'Z')
{
c = tolower(c);
}
The first 'if' didn't get skipped ... it ran, converting a character to upper case ... which the second 'if' statement then converted straight back to lower case again.
The second 'if' statement needs to be an 'else if' instead.
Ahh thank you very much last Chance! I can't believe I missed that, was looking at that for hours. Also sorry this was my first post, I will make sure to utilize proper formatting going forward.