Alright, lets try taking this step by step, I'll help guide you through this:
Alright. Something I don't like:
cout << "Area Inches of Desk " << length*width;
Looks kind of messy to me.
How about making a variable called a, and initializing it to the value of length*width, then printing out a, instead of "couting" length* width like that in a cout statement.
Change that and we'll move on =]
You might want to change system("pause"), to cin.ignore();... It's frowned upon in C++.
cout << "Enter Inches Length of Desk" << endl;
cin >> length;
cout << "Enter Inches Width of Desk" << endl;
cin >> width;
int area = length*width; // Better definition for area
cout << "Area Inches of Desk " << area << endl;
if ( area > 75 ){
total = area + 50; // Add 50 to total, if area is greater than 75
cout << " Additional $50.00 to Total Price "<<endl;
cout << "Total: $" << total ;
}
else{
total = area ;
cout << "Total is: $" << total ;
}
return 0;
Try your hands on other part of the program and let me know what other problems you encounter.
This is a guide, to determining the kind of wood. You may have to use include string class function i.e #include <string.h> or use case switch (by assigning 1 for mahogany, 2 for Oak and 3 for pine). The "switch case" is preferred as it reduces error from user input.
As an aside, I have a problem with the "surface area" math. A desk is a three dimensional object with six surface planes. Determining the surface area requires additional info (height) and a different calculation than L*W*H as that would calculate volume. The right formula would be 2LW+2WH+2LH or 6LW if L=W=H. Bare that in mind as you "help" the OP.
Unless you're going to reuse (length*width) a few times, it's stupid to make a temporary variable for it.
I probably wouldn't call it outright stupid per se. I believe it mostly boils down to preference, and there are advantages and disadvantages associated with it. A disadvantage would be your program is allocating more memory than it should. But there are also some advantages, like the code looks a bit cleaner ( preference of the programmer ). It can also be a bit more readable and improve clarity, and in case you change your mind about reusing the computation then you just do so immediately without having to alter your previous code.
Actually, I use the (length*width) style. In my humble opinion though, I believe it really just depends on the programmer's purpose and preferences. Does he want readability (for maintenance) or efficiency (through saving memory), but it's probably not appropriate to call it stupid just because it's different from how we do things. That's just my opinion on the matter though if you don't mind me saying. =)
Someone mentioned using string and switch? You can't use those together because C++ doesn't recognize strings as a data type. You can use char array strings, but not typical strings.
Oh never-mind, I see what you were saying. In my code I assigned 1 to pine, 2 to oak, and 3 to mahog. I was confused because I thought you meant to use string and switch together.