Function Argument Error
Nov 11, 2014 at 6:45am UTC
Hey so I need to write a program to show functions being called into the main function. When I try to build I get an error saying my printbox function doesn't take two arguments and I'm not sure why. Any help is greatly appreciated.
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,int Width);
void printRangeAndAvg(int Low, int High);
void printBox(int Width);
void printWedge(int Height);
void main()
{
//create variables
int Width;
int Height;
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);
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 height 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;
}
}
Nov 11, 2014 at 6:52am UTC
You declare void printBox(int Width);
with one parameter and pass two in your call
printBox(Height, Width);
Nov 11, 2014 at 6:56am UTC
Yea that's true your prototype takes a single argument while on call in main you are passing to arguments
1 2
void printBox(int Width); //line 9 prototype takes one argument
void printBox (int Height, int Width);///defination takes two args line 71
Nov 11, 2014 at 6:58am UTC
ah I swore I checked that but obviously looked at a different one. Thank you sir. I'm getting other errors now but at least I moved past that one.
Topic archived. No new replies allowed.