1. ## Additions to my program

I have tried on another site to get some input by did not get any help so I am going to try here. I have wrote this for my class and was wondering if there were any additions you could suggest me to improve the working of it.....Beginner here as you can prob tell by the difficulty of this code. Thanks

Code:
```#include <iostream>

using namespace std;

int main()
{
cout <<"Thankyou for using CSE 1284's paint estimator. ";

cout << "\n\nPlease enter following numbers in feet. ";

double roomWidth;
double roomLength;
double roomHeight;

cout << "\nHeight of the room:	";
cin >> roomHeight;
cout << "Width of the room:	";
cin >> roomWidth;
cout << "Length of the room:	";
cin >> roomLength;

double windowHeight;
double windowWidth;

cout << "Height of the window:	";
cin >> windowHeight;
cout << "Width of the window:	";
cin >> windowWidth;

double doorHeight;
double doorWidth;

cout << "Height of the door:	";
cin >> doorHeight;
cout << "Width of the door:	";
cin >> doorWidth;

double doorBoth = doorHeight * doorWidth;
double windowBoth = windowHeight * windowWidth;
double roomAll = roomWidth * roomHeight;
double roomA = roomHeight * roomLength;
double roomB = (roomAll + roomA) * 2;
double gallons = (roomB - (doorBoth + windowBoth)) / 350;
double coat;

cout <<"\nHow many coats of paint will be needed? " ;
cin >> coat;

double exactGallon = coat * gallons;

cout << "\n\n\n " <<exactGallon << " are needed to paint the room with " << coat << " coats. ";
cout << "\n\n ";

return 0;
}```

2. You could prompt for the square foot coverage per gallon. You could prompt for primer. You could check for zeros. You could make all your messages constants and keep them together in one place. You could combine the getdoor and getwindow logic into a function you call, passing the text and returning the area.

Nice job!

Todd

3. The probably biggest single flaw in the program is the lack of error checking. What if I enter "My room's height is 1000 meters!" instead of 1000. The program would not work at all

4. Originally Posted by Todd Burch
You could prompt for the square foot coverage per gallon. You could prompt for primer. You could check for zeros. You could make all your messages constants and keep them together in one place. You could combine the getdoor and getwindow logic into a function you call, passing the text and returning the area.

Nice job!

Todd
thanks for the input. I'm starting to like this forum. Very quick reply's. I'm sure I will be on here for awhile as I learning c++ and taking the class right now and love it.

Originally Posted by Elysia
The probably biggest single flaw in the program is the lack of error checking. What if I enter "My room's height is 1000 meters!" instead of 1000. The program would not work at all
yea your right.(I guess lol) I stated enter the number so hopefully if someone uses it they will enter just a number. I never tested it with a word but if I were to test it with a word what would I have to do for it to work? Or is it to complicated for me right now as I am just learning?

5. Originally Posted by dukebdx12
thanks for the input. I'm starting to like this forum. Very quick reply's. I'm sure I will be on here for awhile as I learning c++ and taking the class right now and love it.
Yes, this forum is very active indeed . . . .

yea your right.(I guess lol) I stated enter the number so hopefully if someone uses it they will enter just a number. I never tested it with a word but if I were to test it with a word what would I have to do for it to work? Or is it to complicated for me right now as I am just learning?
You could try it. Your program will read 0 instead of a number, as will every successive call to cin. Since you don't check for zero, it's entirely possible that you'll get a divide-by-zero error.

You can detect this very easily.
Code:
```if(cin >> whatever) {
// success
}
else {
// failure
}```
Of course, if you want to be very robust, when you detect a failure, you'd want to remove the offending characters from the input stream, and prompt the user for another number, perhaps after printing a stern message about arabic numerals.

You can do this, too. http://faq.cprogramming.com/cgi-bin/...&id=1043284392

And lastly, since you read so many numbers and things, I'd make a function out of it.

6. Nah. Another way to do it is to read a string and convert to a double using strod. You can also check if strtod returns 0 and the user didn't enter 0, then it's invalid data. It's not perfect, but it works.
But it's also the "error factor" in that your hand may slip and you enter some letter by mistake!

7. Originally Posted by Elysia
Nah. Another way to do it is to read a string and convert to a double using strod. You can also check if strtod returns 0 and the user didn't enter 0, then it's invalid data. It's not perfect, but it works.
You can also check, perfectly, if strtod() failed or not. If the end pointer is set to the same thing as the beginning pointer, it didn't read anything. http://linux.die.net/man/3/strtod

See my example in this other thread: http://cboard.cprogramming.com/showp...3&postcount=11

8. That's another way to do it, but it can read one, two, three characters and only half-succeed. So there's a lot of interpretation of like "1a" - is it valid? Should it ignore the "a"? And "1 " - is it valid?
It would read one character and stop, not two. But generally you might think it would read and parse the entire string if it succeeds, but in that case, it wouldn't.

So there's no 100&#37; guarantee method.

9. Originally Posted by dwks
Yes, this forum is very active indeed . . . .

You could try it. Your program will read 0 instead of a number, as will every successive call to cin. Since you don't check for zero, it's entirely possible that you'll get a divide-by-zero error.

You can detect this very easily.
Code:
```if(cin >> whatever) {
// success
}
else {
// failure
}```
Of course, if you want to be very robust, when you detect a failure, you'd want to remove the offending characters from the input stream, and prompt the user for another number, perhaps after printing a stern message about arabic numerals.

You can do this, too. http://faq.cprogramming.com/cgi-bin/...&id=1043284392

And lastly, since you read so many numbers and things, I'd make a function out of it.
got to remember i am very new at this and really only know a limited of things. I read the faq for invalid errors and understood most of the code but some things I havn't seen before in class and really don't know what to with and how to enter into my code. I'm not going to add it to my code just wanted to know what I can do better next time. Thanks

- and I ran it and typed in feet with a number and it did not work. As in the program spit out numbers that are not right.

10. Originally Posted by Elysia
That's another way to do it, but it can read one, two, three characters and only half-succeed. So there's a lot of interpretation of like "1a" - is it valid? Should it ignore the "a"? And "1 " - is it valid?
It would read one character and stop, not two. But generally you might think it would read and parse the entire string if it succeeds, but in that case, it wouldn't.

So there's no 100% guarantee method.
That's up to the programmer to decide. If you wanted to reject something like "1a", you could compare *end with '\0'. (Possibly after skipping over any whitespace.)

- and I ran it and typed in feet with a number and it did not work. As in the program spit out numbers that are not right.
Yeah, that's what will happen if you don't check for errors.