### Totally lost :-/

I am to write a program that determine the amount of cloth in square inches needed to make a certain kind of garment

The instructions state 'Rather than using one big pile of main( ), you need to use functions for these calculation that incorporate pass-by-value parameters. In addition, you need to include various int or double const declarations within your program. Finally, embed your program in a loop so that the calculation can be repeated as often as the user wishes. IN ORDER TO RECEIVE FULL CREDIT, YOU MUST DEFINE AND CALL FUNCTIONS AND PASS ARGUMENTS.'

Pants
2 1/2 square inch per waist size inch of the
person being fitted
1/2 square inch per height inch of the person
being fitted
1/10 square inch per waist size inch of the
person being fitted, if pleaded front is desired
If baggy look is desired, add an extra 10% to
the fabric amount calculated so far

Shirt
2 3/8 square inch per waist size inch of the
person being fitted
4/9 square inch per height inch of the person
being fitted
2 4/5 square inch per arms length inch of the
person being fitted, if long sleeves are desire

Shorts
1 3/10 square inch per waist size inch of the
person being fitted
1/4 square inch per height inch of the person
being fitted
If pockets are desired, add an extra 15% to the
fabric amount calculated so far

So far this is all I have...

 ``1234567891011121314151617181920212223242526272829303132333435363738394041`` ``````#include using namespace std; double fabric(double waist_size, double height_size); int main() { const double pleat = 0.1; double fabric_pants, waist_size, height_size; char ans; cout << "Welcome to the Pants Consumers Union.\n"; cout << "Gimme your waist size in inches: "; cin >> waist_size; cout << "Gimme your height size in inches: "; cin >> height_size; //cout << "Pleaded front? [Y/N]:"; //cin >> ans; //while ((ans == 'Y') && (ans == 'y')); //waist_size = waist_size + (pleat*waist_size); fabric_pants = fabric(waist_size, height_size); cout << "For your pants, you'll need " << fabric_pants << " square inches of fabric!" << endl; return 0; } double fabric(double waist_size, double height_size) { const double waist = 2.5, height = 0.5; double waist_fabric, height_fabric; waist_fabric = waist_size*waist; height_fabric = height_size*height; return (waist_fabric + height_fabric); } ``````

The Output is "SUPPOSED" to be as follows

Tailor Fabric Calculator:

Whaddya want? [P]ants or [S]hirts or shor[T]s: P

Gimme your waist size in inches: 30

Gimme your height size in inches: 72

Baggy Look? [Y/N]: N

For your pants, you'll need 114 square inches of fabric!

Try again? [Y/N]: Y

Tailor Fabric Calculator:

Whaddya want? [P]ants or [S]hirts or shor[T]s: S

Gimme your waist size in inches: 32

Gimme your height size in inches: 50

Long sleeves? [Y/N]: Y
Gimme your arms length in inches: 25

For your shirts, you'll need 168.2222 square inches of fabric!

Try again? [Y/N]: Y

Tailor Fabric Calculator:

Whaddya want? [P]ants or [S]hirts or shor[T]s: T

Gimme your waist size in inches: 35

Gimme your height size in inches: 72

Pockets? [Y/N]: Y

For your shorts, you'll need 73.025 square inches of fabric!

Try again? [Y/N]: N
Use a do-while loop to make the program repeat until the user asnwers 'N' at "try again?". It's the normal approach to ensure an operation is repeated as many times as necessary but at least one time.

The part you commented will never evaluate to true: if 'ans' == 'Y' then it will never be also equal to 'y'. And even if it were to, it would loop forever, as the condition to continue looping never has the chance to change. What you want there is an 'if'.

Personally I'd move the code for pleaded front, long sleeves, etc, inside the functions too.
Basically, the calculation for fabric area for each type (shirt, pants, shorts) can be broken into its own function. In main, ask the user what kind of garment she wants to calculate, then call the right function to do it and print the result.

By putting this code in a loop, you can continually repeat this process until the user wants to quit.

The code might look something like this:

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778`` `````` // note, I did not compile this so there may be syntax errors #include // Define any global constants const double pleat = 0.1; // Functions declared here and implemented after main() double CalcPants(); double CalcShirt(); double CalcShorts; //... in main bool userWantsToContinue = true; while(userWantsToContinue) { // Determine what the user wants string userRequest; cout << "Whaddya want? [P]ants or [S]hirts or shor[T]s: "; cin >> userRequest; double fabricArea = 0; // Check for each type, both upper and lower case if(userRequest == "s" || userRequest == "S") { fabricArea = CalcShirt(); } if(userRequest == "p" || userRequest == "P") { fabricArea = CalcPants(); } if(userRequest == "t" || userRequest == "T") { fabricArea = CalcShorts(); } else { cout << "Error: Invalid input: " << userRequest << endl; continue; // this will go back to the start of the loop -> while(userWantsToContinue) } cout << "You need "<< fabricArea << "square inches" << endl; // Determine if the user wants to go again bool gotUserInput = false; // signals if the user entered a valid yes or no while (!gotUserInput) { cout << "Try again? [Y/N]: "; string tryAgainStr; cin >> tryAgainStr; if(tryAgainStr == "Y" || tryAgainStr == "y") { gotUserInput = true; // the user entered someting valid userWantsToContinue = true; // continue the loop again } else if(/*check for N or n*/) {/**update variables**/ } else { // the user entered bad input, we'll ask the user again for y/n cout << "Error: Invalid input: " << tryAgainStr << endl: } } // end while(!gotUserInput) } // end while(userWantsToContinue) return 0; } // end main // implement the calc functions ``````

Additionally, even the code in the loops could be broken out into their own functions. None of this passes by value but I think that would just complicate things.
Hi,
This was a tremendous help!

I was able to implement the code a little and have a much better grasp of how the program is attempting sort it's logic,
but I am still have a little bit of trouble rounding off the edges,

the roughed out sketch of my current code is as follows

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151`` ``````#include #include #include using namespace std; const double pleat = 0.1; double CalcPants(double waist_size, double height_size); double CalcShirt(double waist_size, double height_size); double CalcShorts(double waist_size, double height_size); int main() { bool userWantsToContinue = true; while(userWantsToContinue) { // Determine what the user wants string userRequest; cout << "Whaddya want? [P]ants or [S]hirts or shor[T]s: "; cin >> userRequest; double fabricArea = 0; // Check for each type, both upper and lower case if(userRequest == "s" || userRequest == "S") { fabricArea = CalcShirt(); } if(userRequest == "p" || userRequest == "P") { fabricArea = CalcPants(); } if(userRequest == "t" || userRequest == "T") { fabricArea = CalcShorts(); } else { cout << "Error: Invalid input: " << userRequest << endl; continue; // this will go back to the start of the loop -> while(userWantsToContinue) } cout << "You need "<< fabricArea << "square inches" << endl; // Determine if the user wants to go again bool gotUserInput = false; // signals if the user entered a valid yes or no while (!gotUserInput) { cout << "Try again? [Y/N]: "; string tryAgainStr; cin >> tryAgainStr; if(tryAgainStr == "Y" || tryAgainStr == "y") { gotUserInput = true; // the user entered someting valid userWantsToContinue = true; // continue the loop again } else if(tryAgainStr == "N" || tryAgainStr == "n") { /**update variables**/ } else { // the user entered bad input, we'll ask the user again for y/n cout << "Error: Invalid input: " << tryAgainStr << endl; } } // end while(!gotUserInput) } // end while(userWantsToContinue) return 0; } // end main double CalcPants(double waist_size, double height_size); { const double waist = 2.5, height = 0.5; double waist_fabric, height_fabric, waist_size, height_size; char ans1, ans2; cout << "Tailor Fabric Calculator:\n"; cout << "Gimme your waist size in inches: "; cin >> waist_size; cout << "Gimme your height size in inches: "; cin >> height_size; cout << "Pleaded front? [Y/N]:"; cin >> ans1,ans2; if (ans1 == 'Y' || ans1 == 'y') waist_fabric + (waist_fabric * pleat) = wasit_frabric; cout << "Baggy Look? [Y/N]:"; cin >> ans2; if (ans2 == 'Y' || ans2 == 'y') ((waist_fabric + height_fabric) * 0.1); waist_fabric = waist_size*waist; height_fabric = height_size*height; return (waist_fabric + height_fabric); } double CalcShirt(double waist_size, double height_size); { const double waist = 2.375, height = 0.44, sleeve_size = 0; double waist_fabric, height_fabric, waist_size, height_size; char ans; cout << "Tailor Fabric Calculator:\n"; cout << "Gimme your waist size in inches: "; cin >> waist_size; cout << "Gimme your height size in inches: "; cin >> height_size; cout << "Long sleeves? [Y/N]:"; cin >> ans; if (ans == 'Y' || ans == 'y') cout << "Gimme your arms length in inches:"; cin >> sleeve_size; waist_fabric = waist_size*waist; height_fabric = ((sleeve_size+ height_size)*height); return (waist_fabric + height_fabric); } double CalcShorts(double waist_size, double height_size); { const double waist = 1.3, height = 0.25; double waist_fabric, height_fabric, waist_size, height_size; char ans; cout << "Pockets? [Y/N]:"; cin >> ans; if (ans == 'Y' || ans == 'y') ((waist_fabric + height_fabric) * 0.15); waist_fabric = waist_size*waist; height_fabric = height_size*height; return (waist_fabric + height_fabric); }``````
I'm glad that helped. Specifically, what trouble are you having? I glanced at the code, and noticed some assignments were off on lines: 93, 100, 145.

As for the calc functions, if only the waist size and height are needed for the calculation, you could ask the user to input that inside the main loop then pass that into your calc functions. Or you could put the waist/height input code into its own function and have each calc function call it. There are a lot of options.

Looking over the code again, I realized it's always good practice to remove duplicate code. This would at least save copy-paste work.
 ``12345678910111213141516171819202122232425`` `````` // return true on yes, false on no, doesn't return until user enters valid response bool AskUseYesOrNo(const string& questionStr) { string ansStr; while(true) { cout << questionStr << ": "; cin >> ansStr; if(ansStr == "Y" || ansStr == "y") { return true; } else if(ansStr == "N" || ansStr == "n") { return false; } else { cout << "Error: Invalid input: " << ansStr << endl; } } // end while(true) } ``````
Hi,
Currently I am getting these errors and I can figure out why

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150`` ``````#include #include #include using namespace std; const double pleat = 0.1; double CalcPants(double waist_size, double height_size); double CalcShirt(double waist_size, double height_size); double CalcShorts(double waist_size, double height_size); int main() { bool userWantsToContinue = true; while(userWantsToContinue) { // Determine what the user wants string userRequest; cout << "Whaddya want? [P]ants or [S]hirts or shor[T]s: "; cin >> userRequest; double fabricArea = 0; // Check for each type, both upper and lower case if(userRequest == "s" || userRequest == "S") { fabricArea = CalcShirt(); } if(userRequest == "p" || userRequest == "P") { fabricArea = CalcPants(); } if(userRequest == "t" || userRequest == "T") { fabricArea = CalcShorts(); } else { cout << "Error: Invalid input: " << userRequest << endl; continue; // this will go back to the start of the loop -> while(userWantsToContinue) } cout << "You need "<< fabricArea << "square inches" << endl; // Determine if the user wants to go again bool gotUserInput = false; // signals if the user entered a valid yes or no while (!gotUserInput) { cout << "Try again? [Y/N]: "; string tryAgainStr; cin >> tryAgainStr; if(tryAgainStr == "Y" || tryAgainStr == "y") { gotUserInput = true; // the user entered someting valid userWantsToContinue = true; // continue the loop again } else if(tryAgainStr == "N" || tryAgainStr == "n") { gotUserInput = false; // the user entered someting valid userWantsToContinue = false; // continue the loop again } else { // the user entered bad input, we'll ask the user again for y/n cout << "Error: Invalid input: " << tryAgainStr << endl; } } // end while(!gotUserInput) } // end while(userWantsToContinue) return 0; } // end main double CalcPants(double waist_size, double height_size); { const double waist = 2.5, height = 0.5; double waist_fabric, height_fabric, waist_size, height_size; char ans1, ans2; cout << "Tailor Fabric Calculator:\n"; cout << "Gimme your waist size in inches: "; cin >> waist_size; cout << "Gimme your height size in inches: "; cin >> height_size; cout << "Pleaded front? [Y/N]:"; cin >> ans1,ans2; if (ans1 == 'Y' || ans1 == 'y') waist_fabric = waist_fabric + (waist_fabric * pleat); cout << "Baggy Look? [Y/N]:"; cin >> ans2; if (ans2 == 'Y' || ans2 == 'y') ((waist_fabric + height_fabric) * 0.1); waist_fabric = waist_size*waist; height_fabric = height_size*height; return (waist_fabric + height_fabric); } double CalcShirt(double waist_size, double height_size); { const double waist = 2.375, height = 0.44, sleeve_size = 0; double waist_fabric, height_fabric, waist_size, height_size; char ans; cout << "Tailor Fabric Calculator:\n"; cout << "Gimme your waist size in inches: "; cin >> waist_size; cout << "Gimme your height size in inches: "; cin >> height_size; cout << "Long sleeves? [Y/N]:"; cin >> ans; if (ans == 'Y' || ans == 'y') cout << "Gimme your arms length in inches:"; cin >> sleeve_size; waist_fabric = waist_size*waist; height_fabric = ((sleeve_size+ height_size)*height); return (waist_fabric + height_fabric); } double CalcShorts(double waist_size, double height_size); { const double waist = 1.3, height = 0.25; double waist_fabric, height_fabric, waist_size, height_size; char ans; cout << "Pockets? [Y/N]:"; cin >> ans; if (ans == 'Y' || ans == 'y') ((waist_fabric + height_fabric) * 0.15); waist_fabric = waist_size*waist; height_fabric = height_size*height; return (waist_fabric + height_fabric); }``````

\\psf\home\documents\visual studio 2010\projects\pizza\pizza\pizza.cpp(29): error C2660: 'CalcShirt' : function does not take 0 arguments
\\psf\home\documents\visual studio 2010\projects\pizza\pizza\pizza.cpp(33): error C2660: 'CalcPants' : function does not take 0 arguments
\\psf\home\documents\visual studio 2010\projects\pizza\pizza\pizza.cpp(37): error C2660: 'CalcShorts' : function does not take 0 arguments
\\psf\home\documents\visual studio 2010\projects\pizza\pizza\pizza.cpp(78): error C2447: '{' : missing function header (old-style formal list?)
\\psf\home\documents\visual studio 2010\projects\pizza\pizza\pizza.cpp(108): error C2447: '{' : missing function header (old-style formal list?)
\\psf\home\documents\visual studio 2010\projects\pizza\pizza\pizza.cpp(134): error C2447: '{' : missing function header (old-style formal list?)

Build FAILED.
pretty self explanatory...
line 29 , 33 , 37 take 0 arguments...look at how you define the functions then please tell us why you do not understand the error.
The other error messages are a little less explanitory..but if you look at the line of the error or the line before it is pretty easy to figure what is wrong you are putting a semi-colon after the function declaration and remember a semicolon means the end of the code therefore how can you have stuff inside the function braces if it has ended before them.
I would remove semi-colons on line 77 , 107, and 133. I think you can fix the other 3 errors yourself though.
Alright, almost there...:)

I was able to debug with out any errors, only now I am getting errors in the program out put

 ```'\\psf\Home\Documents\Visual Studio 2010\Projects\Pizza\Pizza' CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows directory. Whaddya want? [P]ants or [S]hirts or shor[T]s: P Tailor Fabric Calculator: Gimme your waist size in inches: 30 Gimme your height size in inches: 72 Pleaded front? [Y/N]:Y Baggy Look? [Y/N]:N Error: Invalid input: P Whaddya want? [P]ants or [S]hirts or shor[T]s: S Tailor Fabric Calculator: Gimme your waist size in inches: 32 Gimme your height size in inches: 50 Long sleeves? [Y/N]:Y Gimme your arms length in inches:25 Error: Invalid input: S Whaddya want? [P]ants or [S]hirts or shor[T]s: T Pockets? [Y/N]:35 You need 0square inches Try again? [Y/N]: Error: Invalid input: 5 Try again? [Y/N]:```

below is the code

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150`` ``````#include #include #include using namespace std; const double pleat = 0.1; double CalcPants(double waist_size, double height_size); double CalcShirt(double waist_size, double height_size); double CalcShorts(double waist_size, double height_size); int main() { bool userWantsToContinue = true; while(userWantsToContinue) { // Determine what the user wants string userRequest; cout << "Whaddya want? [P]ants or [S]hirts or shor[T]s: "; cin >> userRequest; double waist_size = 0 , height_size = 0, fabricArea = 0; // Check for each type, both upper and lower case if(userRequest == "s" || userRequest == "S") { fabricArea = CalcShirt(waist_size, height_size); } if(userRequest == "p" || userRequest == "P") { fabricArea = CalcPants(waist_size, height_size); } if(userRequest == "t" || userRequest == "T") { fabricArea = CalcShorts(waist_size, height_size); } else { cout << "Error: Invalid input: " << userRequest << endl; continue; // this will go back to the start of the loop -> while(userWantsToContinue) } cout << "You need "<< fabricArea << "square inches" << endl; // Determine if the user wants to go again bool gotUserInput = false; // signals if the user entered a valid yes or no while (!gotUserInput) { cout << "Try again? [Y/N]: "; string tryAgainStr; cin >> tryAgainStr; if(tryAgainStr == "Y" || tryAgainStr == "y") { gotUserInput = true; // the user entered someting valid userWantsToContinue = true; // continue the loop again } else if(tryAgainStr == "N" || tryAgainStr == "n") { gotUserInput = false; // the user entered someting valid userWantsToContinue = false; // continue the loop again } else { // the user entered bad input, we'll ask the user again for y/n cout << "Error: Invalid input: " << tryAgainStr << endl; } } // end while(!gotUserInput) } // end while(userWantsToContinue) return 0; } // end main double CalcPants(double waist_size, double height_size) { const double waist = 2.5, height = 0.5; double waist_fabric = 0, height_fabric = 0; char ans1, ans2; cout << "Tailor Fabric Calculator:\n"; cout << "Gimme your waist size in inches: "; cin >> waist_size; cout << "Gimme your height size in inches: "; cin >> height_size; cout << "Pleaded front? [Y/N]:"; cin >> ans1,ans2; if (ans1 == 'Y' || ans1 == 'y') waist_fabric = waist_fabric + (waist_fabric * pleat); cout << "Baggy Look? [Y/N]:"; cin >> ans2; if (ans2 == 'Y' || ans2 == 'y') ((waist_fabric + height_fabric) * 0.1); waist_fabric = waist_size*waist; height_fabric = height_size*height; return (waist_fabric + height_fabric); } double CalcShirt(double waist_size, double height_size) { const double waist = 2.375, height = 0.44; double waist_fabric = 0, height_fabric = 0, sleeve_size = 0;; char ans; cout << "Tailor Fabric Calculator:\n"; cout << "Gimme your waist size in inches: "; cin >> waist_size; cout << "Gimme your height size in inches: "; cin >> height_size; cout << "Long sleeves? [Y/N]:"; cin >> ans; if (ans == 'Y' || ans == 'y') cout << "Gimme your arms length in inches:"; cin >> sleeve_size; waist_fabric = waist_size*waist; height_fabric = ((sleeve_size+ height_size)*height); return (waist_fabric + height_fabric); } double CalcShorts(double waist_size, double height_size) { const double waist = 1.3, height = 0.25; double waist_fabric = 0, height_fabric = 0; char ans; cout << "Pockets? [Y/N]:"; cin >> ans; if (ans == 'Y' || ans == 'y') ((waist_fabric + height_fabric) * 0.15); waist_fabric = waist_size*waist; height_fabric = height_size*height; return (waist_fabric + height_fabric); }``````
Topic archived. No new replies allowed.