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...


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
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

Pleaded front? [Y/N]: Y

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

// note, I did not compile this so there may be syntax errors

#include <string>

// 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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <iostream>
#include <string>
#include <cmath>
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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

// 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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <iostream>
#include <string>
#include <cmath>
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <iostream>
#include <string>
#include <cmath>
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.