Question

C++ Please    Output values below an amount - functions & arrays No Vectors can be used...

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;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`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.

Add a comment
Know the answer?
Add Answer to:
C++ Please    Output values below an amount - functions & arrays No Vectors can be used...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT