Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am writing a program in C++ in which a user is asked to enter a series of numb

ID: 3625543 • Letter: I

Question

I am writing a program in C++ in which a user is asked to enter a series of numbers into an array (a maximum of 50). The user is then asked to enter a lower threshold number and an upper threshold number. These two numbers are used to filter into three arrays; lower[], which captures all the numbers less than the lower threshold number, upper[], which captures all the numbers greater than the upper threshold number, and middle[] which captures all the numbers between the upper and lower threshold mountains.

The program I have written so far can do all of that. My problem is my output. The program reports the number in each array one line at a time.

Can someone help me fix this please?
MSR

My program follows:

#include <iostream>
using namespace std;


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: (a maximum of 50) ";
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 and the upper threshold number: " << endl;
cin >> t1 >> t2;

if (t2 < t1)
{
int temp = t2;
t2 = t1;
t1 = temp;
}

cout <<t1<<" is the lower threshold number and "<<t2<< " is the upper threshold number ";


for(i = 0; i < numNum; i++){
if(num[i] > t2)
higher[higherCount++] = num[i];

if(num[i] < t1)
lower[lowerCount++] = num[i];

if(t1 < num[i] && num[i] < t2)
middle[middleCount++] = num[i];

}

int j = 0;
for(j = 0; j < numNum; j++)
cout <<"the numbers in the array are "<<num[j]<< " "<<endl;
cout <<" ";
for(j = 0; j < higherCount; j++)
cout <<"the numbers above the upper threshold are "<<higher[j]<< " "<<endl;
cout <<" ";
for(j = 0; j < lowerCount; j++)
cout <<"the numbers below the lower threshold are "<<lower[j]<< " "<<endl;
cout <<" ";
for(j = 0; j < middleCount; j++)
cout <<"the numbers between the lower threshold an upper threshold are "<<middle[j]<< " "<<endl;
cout <<" ";

}

system ("PAUSE");
return 0;
}

Explanation / Answer

#include <iostream>
using namespace std;


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: (a maximum of 50) ";
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 and the upper threshold number: " << endl;
cin >> t1 >> t2;

if (t2 < t1)
{
int temp = t2;
t2 = t1;
t1 = temp;
}

cout <<t1<<" is the lower threshold number and "<<t2<< " is the upper threshold number ";


for(i = 0; i < numNum; i++){
if(num[i] > t2)
higher[higherCount++] = num[i];

if(num[i] < t1)
lower[lowerCount++] = num[i];

if(t1 < num[i] && num[i] < t2)
middle[middleCount++] = num[i];

}

int j = 0;
cout <<"the numbers in the array are ";
for(j = 0; j < numNum; j++)
cout <<num[j]<< " ";
cout<<endl;
cout <<"the numbers above the upper threshold are ";
for(j = 0; j < higherCount; j++)
cout <<higher[j]<< " ";
cout<<endl;
cout <<"the numbers below the lower threshold are ";
for(j = 0; j < lowerCount; j++)
cout<<lower[j]<< " ";
cout<<endl;
cout <<"the numbers between the lower threshold an upper threshold are ";
for(j = 0; j < middleCount; j++)
cout<<middle[j]<< " ";
cout<<endl;


}

system ("PAUSE");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote