Programming help

closed account (G2zhRXSz)
Hi, does anyone know how to complete the following problem?? Any help is greatly appreciated!

#include <iostream>
#include <iomanip>

using namespace std;
int main() {
string length, width;
int count;
count = 0;
for(count =0; count <4; count++)
{
cout << "Welcome to Rectangle Draw It!!\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n";
cout << "Enter a value from 1 to 20...\n";
cout << "Please enter the length of the rectangle <Enter 99 to Exit> > \n";
cin >> length;

cout << "Please enter the width of the rectangle <Enter 99 to Exit> > \n";
cin >> width;
}
//E) Validate user input (must input 1 through 20 (inclusive) or 99), loop if value is invalid

//while (length <= 20 || length >= 0 || length == 99)
Last edited on
Yes, we know how to do it.

^ I was gonna leave it at that and just LOL but I thought that'd be too mean.

You should do one thing at a time, you need to do the things you specified with letters. A welcome screen using cout, ask for length of the rectangle and get it with cin, make a condition (best done through a loop) to check if the input is correct.

Write some code, try to do it. If you get stuck somewhere, then post what you have for others to help. But for now, don't be afraid to simply start coding. You may feel like you don't know how to begin (so I told you), you may feel like everything you're coding is completely wrong, you may even feel like your cat is judging you. But you should simply start coding, whether right or wrong you'll learn from it. If you're not sure how to do something, try to do it anyway. If you get stuck, then Google is your friend or you can make a post.

Good luck
closed account (G2zhRXSz)
Thanks!!
Last edited on
I'm not sure why count loops from zero to 4. Let us know your plan with that.

Do you intend to take the input 4 times, or draw 4 rectangles?

I sense this is not where your loop should be constructed.

The type for length and width should probably not be strings, because you use numeric input (even as a command for exit). The instructions tell you to use integers, so declare them as integers.

Look at points D and E, then focus on

1
2
3

cin >> length;


E tells you to validate the LENGTH, loop if out of range or exit.

So, consider starting a loop that does not ever terminate unless length is valid (or 99 causes an exit).

You'll need to consider an error message, then re-print the instruction/request, perhaps something like:


1
2
3
4
5
6
7
8
9
10
11

while( length < 1 || length > 20 )
{
  cout << "Enter a value from 1 to 20...\n";
  cout << "Please enter the length of the rectangle <Enter 99 to Exit> > \n";
  cin >> length;

  if ( length == 99 ) return 0;
 }
 

Assume length is an integer, and IT IS INITIALIZED TO ZERO.

This exits the program when 99 is entered.

It loops if length is not in the correct range.


If you get that much, reconsider the width input with something similar.
Last edited on
Look at points D and E, then focus on

cin >> length;

E tells you to validate the LENGTH, loop if out of range or exit.
closed account (G2zhRXSz)
Thank you for the help!! The loops were a big part of why the program was not running correctly.
Topic archived. No new replies allowed.