Using the void function I am trying to write a program in which the user is aske
ID: 3625400 • Letter: U
Question
Using the void function I am trying to write a program in which the user is asked1. How many numbers are you going to enter?
2. Please enter your numbers.
The user is then asked to choose a lower threshold (t1) and an upper threshold (t2). All numbers entered will be divided into three arrays. The lower array are all the numbers less than t1, the upper array are all the numbers greater than t2, in the middle array are all the numbers between t1 and t2.
I am trying to use a function called
void PrintArray (array[], size[])
to print out all three arrays.
Unfortunately I cannot get my program to compile. I keep getting an invalid conversion from int to int error at the end of my program.
Please help me. My program is as follows.
#include <iostream>
using namespace std;
void PrintArray(int array[], int size[])
{
{int num[50], lower[50], higher[50], middle[50], numNum, lowerCount = 0, higherCount = 0, middleCount = 0, i, t1, t2;
for(i = 0; i < numNum; i++){
if(num[i] > t2){
higher[higherCount++] = num[i];
}
if(num[i] < t1){
lower[lowerCount++] = num[i];
}
else{
middle[middleCount++] = num[i];
}
}
}
}
int main ()
{
int num[50], lower[50], higher[50], middle[50], numNum, lowerCount = 0, higherCount = 0, middleCount = 0, i, t1, t2;
cout <<"Please enter how many numbers to be entered: ";
cin >> numNum;
cout <<numNum<< " are being entered into the array..."<<endl;
cout <<"Please enter your numbers: ";
for(i = 0; i < numNum; i++){
cin >>num[i];
cout <<"Please enter the lower threshold number: ";
cin >> t1;
cout <<t1<<" Is the lower threshold number ";
cout <<"Please enter the upper threshold number: ";
cin >> t2;
cout <<t2<<" Is the upper threshold number ";
PrintArray(num, numNum);
}
system ("PAUSE");
return 0;
}
Explanation / Answer
//Here you go it should compile and run now. Your error was that your PrintArray declaration was two arrays when you were only passing in one array and a int #include using namespace std; void PrintArray(int array[], int size) { {int num[50], lower[50], higher[50], middle[50], numNum, lowerCount = 0, higherCount = 0, middleCount = 0, i, t1, t2; for(i = 0; i t2){ higher[higherCount++] = num[i]; } if(num[i]Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.