Help with do while loop

Simple program where I have to output the lowercase of an uppercase letter and vice versa. Can anyone tell me what to exactly put in the while statement so that the loop will run? That is where the problem seems to be coming from.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <conio.h>
#include <ctype.h>
using namespace std;
char l;
int main()
{
cout << "Enter a lowercase or uppercase letter: " << endl;
cin >> l;
do
{
if(isalpha(l))
{
   if (isupper(l))
      {l = tolower(l);}
   else
       {l = toupper(l);}           
}
while ( isalpha(char l);
}
 getch();
 return 0;   
}


//Sure its a very simple fix. I'm just fairly new to this stuff

Here is the exact same program, just not in the form of a loop. It runs fine

#include <iostream>
#include <conio.h>
#include <ctype.h>
using namespace std;
char l;

int main()
{
cout << "Enter a lowercase or uppercase letter: " << endl;
cin >> l;

if(isalpha(l))
{
if (isupper(l))
{l = tolower(l);}
else
{l = toupper(l);}

cout << l;
}
else
{cout << "Incorrect input";}
getch();
return 0;
}
This should work now.

#include <iostream>
#include <conio.h>
#include <ctype.h>
using namespace std;
int main()
{
char l;
do{
cout << "Enter a lowercase or uppercase letter: " << endl;
cin >> l;
if(isalpha(l))
{
if (isupper(l))
{
l = tolower(l);
}
else
{
l = toupper(l);
}
cout << l<<endl;
}
}

while(l!='0');
{
getch();
return 0;
}
}
Corrected code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <conio.h>
#include <ctype.h>
using namespace std;
char l;
int main()
{
	cout << "Enter a lowercase or uppercase letter: " << endl;
	cin >> l;
	do
	{
		if (isalpha(l))
		{
			if (isupper(l))
			{
				l = tolower(l);
			}
			else
			{
				l = toupper(l);
			}
		}
		
	}
	while (isalpha(l)); // Observe you had firstly the while 
	                    //positioned in the closing brace of if(isalpha).
	                    // Second you were sending in a already declared
	                    // varible with another declaration.
	_getch(); // getch() is also depreciated use _getch()
	return 0;
}

Last edited on
Thank you both! Figured it out, very helpful. And thank you CodeGoggles for the pointers
Please mark thread solved when happy with responses makes it easier for others to help :P
And you are most welcome.
Last edited on
Topic archived. No new replies allowed.