Function arguments too many arguments

Hey so I just needed some quick help on this. I got this code that I'm demonstrating calling functions in main. I have a function to prompt for the height and then in main I'm trying to prompt for the width with parameters between the height+1 and 20. but when I try to put these in the says too many arguments. So I'm not sure how to change this, when I build I get this pop up:

Run-Time Check Failure #3 - The variable 'Height' is being used without being initialized.

but when I press continue it works but has 2 messages asking for height.

any help would be greatly appreciated, I've had to spend my whole weekend rebuilding my roof and haven't had the chance to work on this as much as I should.

EDIT
Also here is an example of the main function I'm suppose to use but it doesn't seem to work for me:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

cout << "Enter box height (between 3 and 10): ";

    boxHeight = getInteger(3, 10);

cout << "Enter box width (between " << boxHeight << " and 20): ";

    boxWidth = getInteger(boxHeight + 1, 20);


    printRangeAndAverage( ….. );

    printBox( …. );
    printWedge( … );


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
#include<iostream>
#include<iomanip>

using namespace std;

// function prototyping
int getInteger(int Height);
void printRangeAndAvg(int Low, int High); 
void printBox(int Height, int Width); 
void printWedge(int Height);

void main()
{
	//create variables
	int Width;
	int Height;
	
cout << "Enter box height (between 3 and 10): ";
Height = getInteger(Height);
cout << "Enter box width (between " << Height << " and 20): ";
    Width = getInteger(Height);
	printRangeAndAvg(Height, Width);
    printBox(Height, Width);
    printWedge(Height);

	//keep the console open
	cin.get();
	cin.ignore();
}

int getInteger(int Height)
{
	//prompt user for integer between low and high value
	cout << "Enter a box height(between 3 and 10):";
	cin >> Height;

	//prompt user to repeat height if out of bounds
	while(Height  < 3 || Height > 10)
	{
		cout << "That number is out of bounds: Try again: ";
		cin >> Height;
	}
	return Height;
}

void printRangeAndAvg(int Height, int Width)
{
	int NumSum = 0;
	int NumCount = 0;
	float Average;

	//output the integers between height and width
	cout << "\nThe integers between " << Height << " and " << Width
	<< " are:" << endl <<"\t";
	//calculate the number of numbers between height and width
	NumCount = (Width - Height) + 1;

	//calculate sum  of integers between height and width
	for (int i=Height; i<=Width; i++)
	{
		cout << i << " ";
		NumSum = NumSum+i; 
	}
	cout << endl;

	//calculate the average of numbers between height and width 
	Average = static_cast<float>(NumSum) / NumCount;
	cout << "and the average of those numbers is " << Average << endl << endl;
}

void printBox(int Height, int Width)
{
	//define local variable
	char Asterisk = '*';

	//output hollow rectangle with user input height and width
	cout << Asterisk << setw(Width-1) << setfill ('*') << Asterisk << endl;
	for(int a=0; a<Height-2; a++)
	{
		cout << Asterisk << setw(Width-1) << setfill(' ') << Asterisk << endl;
	}
	cout << Asterisk << setw(Width-1) << setfill ('*') << Asterisk << endl;
	cout << endl;
}

void printWedge(int Height)
{
	//Output triangle with row = height, starting with 2 asterisks on top
	for (int x=1; x<=Height; x++)
	{

		for(int y=1; y<=x+1; y++)
				{
					cout << "*";
				}
		cout << endl;
	}
}
Last edited on
closed account (SECMoG1T)
Remove line 34  2 messages asking for height.
Ok thanks, I just tried but now it doesn't prompt for the width.
closed account (SECMoG1T)
Repost your modified code please can't understand why is that.
I actually Figured it out, had to change some but it finally works. Thanks a lot for the help Andy. Had some trouble but finally got it. Here's the final 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
/*
Program Name: Function Fun
Programmer: Kevin Bond
Date: 11-10-14
Purpose:
Use functions to implement the different parts of loop fun
*/

#include<iostream>
#include<iomanip>

using namespace std;

// function prototyping
int getInteger(int Low, int High);
void printRangeAndAvg(int Low, int High); 
void printBox(int Height, int Width); 
void printWedge(int Height);

void main()
{
	//create variables
	int Width;
	int Height;
	
	// prompt for height and width using getinteger function
	cout << "Enter box height (between 3 and 10): ";
	Height = getInteger(3, 10);
	cout << "Enter box width (between " << Height << " and 20): ";
	Width = getInteger(Height+1, 20);

	//output results of other functions
	printRangeAndAvg(Height, Width);
    printBox(Height, Width);
    printWedge(Height);

	//keep the console open
	cin.get();
	cin.ignore();
}

//================================================================
// Function:    getInteger
// Description: Prompt user to repeat input of Height and Width if 
//				out of bounds 
//Arguments: Low (int), High (int) -sets low and high paramenters
// Return value: Prompt to repeat if out of bounds
//=================================================================*/
int getInteger(int Low, int High)
{
	int Height;
	cin >> Height;

	//prompt user to repeat if out of bounds
	while(Height  < Low || Height > High)
	{
		cout << "That number is out of bounds: Try again: ";
		cin >> Height;
	}
	return Height;
}

//================================================================
// Function:    printRangeAndAvg
// Description: Determines integers between height and width, the
// sum of them and average of the integers 
// Input Arguments: Height, Width (int) - the integers entered by the user
// Return value: outputs All integers between Height and Width, 
//				 the sum and the average of those integers
//=================================================================*/
void printRangeAndAvg(int Height, int Width)
{
	//define local variables
	int NumSum = 0;
	int NumCount = 0;
	float Average;

	//output the integers between height and width
	cout << "\nThe integers between " << Height << " and " << Width
	<< " are:" << endl <<"\t";
	//calculate the number of numbers between height and width
	NumCount = (Width - Height) + 1;

	//calculate sum  of integers between height and width
	for (int i=Height; i<=Width; i++)
	{
		cout << i << " ";
		NumSum = NumSum+i; 
	}
	cout << endl;

	//calculate the average of numbers between height and width 
	Average = static_cast<float>(NumSum) / NumCount;
	cout << "and the average of those numbers is " << Average << endl << endl;
}

//================================================================
// Function:    printBox
// Description: Prints out a rectangle of asterisks with user Height and Width
// Arguments: Height (int), Width(int)- integers set by user
// Return value: Prints rectangle with user Height and Width
//=================================================================*/
void printBox(int Height, int Width)
{
	//define local variable
	char Asterisk = '*';

	//output hollow rectangle with user input height and width
	cout << Asterisk << setw(Width-1) << setfill ('*') << Asterisk << endl;
	for(int a=0; a<Height-2; a++)
	{
		cout << Asterisk << setw(Width-1) << setfill(' ') << Asterisk << endl;
	}
	cout << Asterisk << setw(Width-1) << setfill ('*') << Asterisk << endl;
	cout << endl;
}


//================================================================
// Function:    printWedge
// Description: prints a triangle with user height, starting with 2 asterisks
//				on top and adding 2 asterisks per row
// Arguments: Height(int) - sets number of rows to user height
// Return value: Prints Triangle with set criteria
//=================================================================*/
void printWedge(int Height)
{
	//Output triangle with row = height, starting with 2 asterisks on top
	for (int x=1; x<=Height; x++)
	{
		for(int y=1; y<=x; y++)
				{
					cout << "**";
				}
		cout << endl;
	}
}
Topic archived. No new replies allowed.