Computer Problems? Computing.Net has over
1,000,000 posts about all things technology related! Over 90% answered within 24 hours!
Click here to start participating now! Also, be sure to check out the
New User Guide .
Help Making C++ Rectangle
Comment: I have to build a rectangle that looks like this:
********** ********** **********
per user input. Here is the code I have. Right now it only shows up similar to this:
*************** * * *
#include <iostream>
using namespace std;
void main() {
int iHeight = 0;
int iWidth = 0;
int iHeightCount = 1;
int iWidthCount = 1;
cout << "Enter the height of the rectangle: ";
cin >> iHeight;
cout << "Enter the width of the rectangle: ";
cin >> iWidth;
cout << endl;
while (iHeightCount <= iHeight)
{
while (iWidthCount <= iWidth)
{
cout << "*";
++iWidthCount;
}
cout << "*";
++iHeightCount;
cout << endl;
}
cout << endl;
}
All help is greatly appreciated!
Sponsored Link
Response Number 1
Name: Razor2.3
Date: October 10, 2009 at 10:39:50 Pacific
Reply: Use for loops. it'll solve your problem, and it's considered a better coding practice (because it avoids this bug).
0
Response Number 2
Name: kool_zero
Date: October 10, 2009 at 10:52:13 Pacific
Reply: I have to use while loops :( Gotta love teachers haha
0
Response Number 3
Name: Razor2.3
Date: October 10, 2009 at 10:53:47 Pacific
Reply: Fine then. You never reset the value of iWidthCount .
0
Response Number 4
Name: kool_zero
Date: October 10, 2009 at 11:41:52 Pacific
Reply: so don't increment the iWidthCount? or what? I am confused?
0
Response Number 5
Name: Razor2.3
Date: October 10, 2009 at 12:12:51 Pacific
Reply: so don't increment the iWidthCount? Only if you want to end up in an infinite loop.
I am confused[.] Well, if you don't mind the mangled output, you could see what is happening by changing the test on your second while to this:while ((cout << iWidthCount) && iWidthCount <= iWidth) (As you might have guessed, it shows you the value of iWidthCount whenever the inner loop is tested.)
Alternatively, you could just use VS' debugger to go though your code step-by-step, and watch your variables.
0
Related Posts
Response Number 6
Name: kool_zero
Date: October 11, 2009 at 15:46:01 Pacific
Reply: Could you please post what the code should look like because I am still having problems?
0
Response Number 7
Name: Razor2.3
Date: October 11, 2009 at 15:52:53 Pacific
Reply: Depends on how you answer these questions: 1) What is the value of iWidthCount at the start of the inner while ?
2) What is the value of iWidthCount when you break out of the inner while ?
3) What is the value of iWidthCount at the start of the inner while the second time through the outer loop?
4) Must you use nested while s, or did he just demand two while loops?
0
Sponsored Link
Use following form to reply to current message:
Login or Register to Reply
Login Register
Sponsored links
Results for: Help Making C++ Rectangle
Help with C++ char's Summary : hello, i have dev c++ and visual studio 6.0 and i want to make a c++ program that will let the user input a string of characters (like a name) and then have the program display that string. my proble... www.computing.net/answers/programming/help-with-c-chars/9909.html
help in c language Summary : can u help me to solve this proplem: Write a C program (give it the name: family.c) which receives no arguments. The program should fork exactly two children. One child should sleep for 2 seconds and ... www.computing.net/answers/programming/help-in-c-language/14135.html
Need help with C programming Summary : Very new to C and need help ASAP
... www.computing.net/answers/programming/need-help-with-c-programming/6970.html