|
From: Schedler, K. <Kur...@hi...> - 2001-07-19 18:44:10
|
I have to wonder why you multiplied 9 times the asterisk character. I can
only presume you thought that would give you nine asterisks in a row. I
imagine that your code spit out a strange number and then hit an infinite
loop, continuously printing asterisks to the screen.
int main()
{
int lines = 9;
int stars;
while (lines > 0)
{
stars = lines;
while (stars > 0)
{
putchar('*');
stars--;
}
putchar('\n');
lines--;
}
return 0;
}
which gives this output:
*********
********
*******
******
*****
****
***
**
*
-----Original Message-----
From: Tre...@ao... [mailto:Tre...@ao...]
Sent: Thursday, July 19, 2001 10:35 AM
To: dev...@li...
Subject: [Dev-C++] nested loop
I have to write a program that uses a nested while loop in order to display
lines of asterisks from 9 to 1. Here is the code.....can anyone help me? I
don't understand how to make this work.
#include<iostream>
int main()
{
int asterisk = 9;
int counter = 9;
char ast = '*';
asterisk = (asterisk * ast);
while (counter > 0)
{
cout << asterisk << endl;
counter = counter - 1;
asterisk = asterisk - ast;
while (asterisk > 0)
{
cout << "*" << "" << endl;
}
}
return 0;
}
"The sender believes that this E-mail and any attachments were free of any
virus, worm, Trojan horse, and/or malicious code when sent. This message
and its attachments could have been infected during transmission. By
reading the message and opening any attachments, the recipient accepts full
responsibility for taking protective and remedial action about viruses and
other defects. The sender's employer is not liable for any loss or damage
arising in any way from this message or its attachments."
|