View Single Post
Old 10-14-2006, 08:26 AM   #6 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
Quote:
now i want to improve it by limiting the user to take only digits from 0 - 9
Code:
while(cin >> size)
{
  if(size < 0 || size > 9)
    {
      cout << "Sorry your given number isn't within acceted limits (0-9)" << endl;
      continue;
    }
...
Quote:
After the output is shown , there is a repsone taken from user

Press any key to exit
hmm... shouldn't this run untill the user explicit exit, or should it just be a single run ??
To accommodate a request running untill the user explicit exits, you would take percausions like
Code:
cout << "Please enter a number between 0 and 9, use -1 to quit: ";
while(cin >> size && size >= 0)
...
To accommodate the user unly beeing asked once, and then exit uppon further user interaction, just eliminate your while clause, and simply read from the user, check for valid number, and then print your pyramid.
Then query the user "press anythign to quit" and simply just let the program terminate uppon next linefeed.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote