C++ Please Output values below an amount - functions & arrays
No Vectors can be used since we haven't learned them yet !!
Write a program that first gets a list of 10 integers from input. . Then, get one more value from the input, and output all integers less than or equal to that value.
Ex: If the input is:
5 50 60 140 200 75 100 22 57 83 50
the output is:
5 50 22
The first 10 numbers create the list. The last number, 50 indicates that the program should output all integers less than or equal to 50, so the program outputs 5, 50 and 22. For coding simplicity, follow every output value by a space, including the last one.
Such functionality is common on sites like Amazon, where a user can filter results.
Write your code to
define and use two functions:
void GetUserValues( int userValues[ ] )
void OutputIntsLessThanOrEqualToThreshold(const int userValues[ ],
int upperThreshold)
Use a global constant SIZE for the size of the array. '''const int SIZE = 10;''' Making the constant global, allows all functions to have access and use the constant. Utilizing functions will help to make main() very clean and intuitive.
#include
using namespace std;
// global constant for size of array
const int SIZE = 10;
/* Define your functions here */
int main() {
// declare variables and array
// call GetUserValues
// read upperThreshold value
// call OutpuIntsLessThanOrEqualTo Threshold
return 0;
}
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
#include <iostream>
using namespace std;
// global constant for size of array
const int SIZE = 10;
/* Define your functions here */
void GetUserValues( int userValues[ ] )
{
for(int i=0;i<SIZE;i++)
cin>>userValues[i];
}
void OutputIntsLessThanOrEqualToThreshold(const int userValues[ ],
int upperThreshold)
{
for(int i=0;i<SIZE;i++)
{
if(userValues[i]<=upperThreshold)
cout<<userValues[i]<<" ";
}
cout<<endl;
}
int main() {
// declare variables and array
int arr[SIZE],num;
// call GetUserValues
GetUserValues(arr);
// read upperThreshold value
cin>>num;
// call OutpuIntsLessThanOrEqualTo Threshold
OutputIntsLessThanOrEqualToThreshold(arr,num);
return 0;
}
Kindly revert for any queries
Thanks.
C++ Please Output values below an amount - functions & arrays No Vectors can be used...