Error else with out a previous if?

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

int main()
{

char letter;
cout << "Enter a character? ";
cin >> letter;

if (islower(letter));
{
cout << "\n The letter is a lower case " << letter << endl;
cout <<"The upper case equivalent is "<< static_cast<char> (toupper(letter)) <<endl;

else if
{

cout << "\n The letter is a Upper case " << letter << endl;
cout<<"The lower case equivalent is "<< static_cast<char> (tolower)letter)) <<endl;
}
}
if (isalpha(letter));
cout << "\nThe character is a letter" << endl;

if (isalnum(letter));
cout << "\nThe character is a number and a letter" << endl;

system("pause");
return 0;
}
If you have a semicolon after an if statement, it counts as the one-liner statement and effectively nullifies your if statements. You have a semicolon after just about all of your if statements.

Also, either it's "else" or "else if(...)", not just "else if"
this belongs to beginner subforum...
anyway int this line
 
if (islower(letter));


remove that ';'

and here
1
2
3
4
5
6
7
8
9
10
11
12
if (islower(letter)) //note that i deleted that ';'
{
cout << "\n The letter is a lower case " << letter << endl; 
cout <<"The upper case equivalent is "<< static_cast<char> (toupper(letter)) <<endl; 
// check out where your else if is.... (INSIDE the code where if is true)
          else if
         {

           cout << "\n The letter is a Upper case " << letter << endl; 
          cout<<"The lower case equivalent is "<< static_cast<char>(tolower)letter)) <<endl; 
          }
}


else if must be out of braces, so this is correct way

1
2
3
4
5
6
7
8
9
10
if (islower(letter))
{/*beginning of code where if is true*/
cout << "\n The letter is a lower case " << letter << endl; 
cout <<"The upper case equivalent is "<< static_cast<char> (toupper(letter)) <<endl; 
}/*end of code where if is true*/
else if (...) /*note that i added braces and three dots (instead of dots place the condition), if u dont have condition for that part of code remove if and remove braces with dots*/
{//note that u had put this code INSIDE the code where if is true, so it couldn't find if to bind
cout << "\n The letter is a Upper case " << letter << endl; 
cout<<"The lower case equivalent is "<< static_cast<char> (tolower)letter)) <<endl; 
}
Last edited on
Topic archived. No new replies allowed.