93.8k views
2 votes
Write a program that gets a list of integers from a user. First, the user should be asked to enter the number of integers to be stored in a list. Then your program should ask for these integers and store them in the list. Finally, the program should ask the user to enter a sentinel value that will be used to search through the integers in the list which are greater than the sentinel value. For example: If the input is: 7 50 60 140 200 75 100 172 70 the output is: 140 200 75 100 172 The 7 indicates that there are seven integers in the list, namely 50 60 140 200 75 100 172. The 70 indicates that the program should output all integers greater than 70, so the program outputs 140 200 75 100 172. You should use methods in addition to the main method. getListValues to get and store the values from the user printListValuesGreaterThanSentinal to print the values found to be greater than the sentinel value.

User Berliner
by
5.7k points

1 Answer

6 votes

Answer:

#include <iostream>

using namespace std;

void insert(int *arr, int num);

int n;

void returnGT(int arr[]);

int main(){

cout<< "Enter the number of integers: "<<endl;

cin>>n;

int num[n];

insert(num, n);

returnGT(num);

}

void insert(int *arr, int num){

for (int i = 0; i < num; i++){

cout<< "Enter item "<< i + 1 << " : ";

cin>> arr[i];

}

}

void returnGT(int arr[]){

int sentinel;

cout<< "Enter sentinel: ";

cin>> sentinel;

for (int i = 0; i < n; i++){

if (arr[i] > sentinel){

cout<< arr[i] << " ";

}

}

}

Step-by-step explanation:

The C++ source code defines an array of integer values, the program prompts for user input for the array size and the sentinel value to fill the array with input values and output integer values greater than the sentinel.

User Boherna
by
6.4k points