Need help with aterik loops
Basically I need to use loops to print the letters "T" "O" and "L". the program ask for a size and the letters. Any help would be appreciated.
Code:
#include<iostream>
using namespace std;
int main()
{
char T, O, L;
char letter;
int number, size;
size = number % 2;
cout << "Welcome to the letter printer." << endl;
cout << "Enter the size : " << endl;
cin >> size;
while (size <= 5 || size == 0)
{
cout << "Invalid size. Enter the size again: ";
cin >> size;
}
cout << "Enter the letter: " << endl;
cin >> letter;
while(letter != 'T' && letter != 'O' && letter != 'L')
{
cout << "Invalid Letter. Enter the letter again:";
cin >> letter;
{
while (letter == 'T')
{
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
cout << "*";
}
cout << endl;
}
}
}
}
Re: Need help with aterik loops
When posting code, please use code tags so that the code is readable. Go advanced, select the formatted code and click '#'.
What issues are you having - compile errors, run time problems??
Code:
int number, size;
size = number % 2;
You are using number to calculate the value of size, but at this point in the program number hasn't been initialised with a value so when used as part of the size calculation it's value is unknown and hence so is the value of size. But you then go on to enter a value for size which overwrites its previous value.
Code:
while (size <= 5 || size == 0)
If size is 0 then this is less than 5, so the test for equality to 0 is not needed.
Code:
while(letter != 'T' && letter != 'O' && letter != 'L')
{
cout << "Invalid Letter. Enter the letter again:";
cin >> letter;
{
If an invalid letter is entered then an error message is displayed, but then the code continues - it doesn't loop over the while again. Look at how the test for invalid size was coded.
For displaying the letter, you are going to have to decide how these letters are to be constructed from *. The code you have just displays a block of *.
eg for T, you need to display size * on one line and then for the next size - 1 lines display one * in the correct place.
Re: Need help with aterik loops
What's the point of this line?
size = number % 2;
Re: Need help with aterik loops
Hello guys! I'm working on very important project now and have problems with aterik loops too. I will try to use you advice, maybe it will help to fix errors in my program. Many thanks for useful link, I was trying to find answers at this [web site address removed] and http://forums.codeguru.com/showthrea...ork-assignment, but there is anything useful for problem in my case.