Question

#include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void...

#include <iostream>

using namespace std;

const int SIZE = 10;

void displayGreaterThan(int[], int);

void displaySmallerThan(int[],int);

void displayArrayContent(int[]);

void displayLargestValue(int[]);

void displaySmallestValue(int[]);

int main(){

  

int number;

  

int numbers[SIZE] = {9,1,90,98,53,22,76,29,37,65};

cout <<"Enter a number: ";

cin >> number;

cout << endl;

  

displayGreaterThan(numbers,number);

cout << endl;

displaySmallerThan(numbers,number);

cout << endl;

displayArrayContent(numbers);

cout << endl;

displayLargestValue(numbers);

cout << endl;

displaySmallestValue(numbers);

cout << endl;

  

return 0;

  

  

}

void displayGreaterThan(int value[],int num){

cout << " All larger value(s)than" << num << ":" << endl;

  

for(int index = 0;index < SIZE;index++){

if(value[index] < num){

cout << value[index] << "";

}

}

  

//cout << " All larger value(s)than" << num << ":" << endl;

  

  

}

void displaySmallThan(int value[], int num){

cout << " All Smaller value(s)than" << num << ":" << endl;

for(int index = 0; index < SIZE; index++){

if(value[index] < num){

cout << value[index] << "";

}

}

  

//cout << " All Smaller value(s)than" << num << ":" << endl;

}

void displayArrayContent(int values[]){

  

for(int index = 0; index < SIZE; index++){

  

cout << values[index] << "" << endl;

}

}

void displayLargestValue(int values[]){

int num = values[0];

for(int index = 0; index > SIZE; index++){

if(values[index] > num){

num = values[index];

}

}

  

cout << " Largest value in array is " << num << endl;

  

  

}

void displaySmallestValue(int values[]){

int num = values[0];

for(int index = 0; index < SIZE; index++){

if(values[index] < num){

num = values[0];

}

}

  

cout << " Smallest value in array is " << num << endl;

}

Can someone tell me what happening to my c++ program? It keep telling me build fail.

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

Please follow the code for the changes made. The mistake you made is the function name for function implementation is

different from the function name you declared.

#include<bits/stdc++.h>
#include <iostream>

using namespace std;

const int SIZE = 10;
/*Function declarations*/
void displaySmallerThan(int[],int);
/*Function declarations*/
void displayGreaterThan(int[], int);
/*Function declarations*/
void displayArrayContent(int[]);
/*Function declarations*/
void displayLargestValue(int[]);
/*Function declarations*/
void displaySmallestValue(int[]);
int main(){

int number;
int numbers[SIZE] = {9,1,90,98,53,22,76,29,37,65};
int*numberss;
numberss=numbers;
cout <<"Enter a number: ";
cin >> number;
cout << endl;
  
/*function call*/
displayGreaterThan(numberss,number);
cout << endl;

/*function call*/
displaySmallerThan(numberss,number);
cout << endl;

/*function call*/
displayArrayContent(numberss);
cout << endl;

/*function call*/
displayLargestValue(numberss);
cout << endl;

/*function call*/
displaySmallestValue(numberss);
cout << endl;

return 0;

}

void displayGreaterThan(int value[],int num){
cout << " All larger value(s)than" << num << ":" << endl;

  

for(int index = 0;index < SIZE;index++){
if(value[index] < num){
cout << value[index] << "";
}
}

//cout << " All larger value(s)than" << num << ":" << endl
}

/*Mistake you made is the function displaySmallerThan implementation switch
wrong function name as displaySmallThan.

you used as void displaySmallThan(int value[], int num)

*/
void displaySmallerThan(int value[], int num){
cout << " All Smaller value(s)than" << num << ":" << endl;
for(int index = 0; index < SIZE; index++){
if(value[index] < num){
cout << value[index] << "";
}
}

  

//cout << " All Smaller value(s)than" << num << ":" << endl;

}

/*fucntion to display the contents of the array*/
void displayArrayContent(int values[]){
for(int index = 0; index < SIZE; index++){
cout << values[index] << "" << endl;
}
}

/*Function to display the largerst value*/
void displayLargestValue(int values[]){
int num = values[0];

for(int index = 0; index > SIZE; index++){
if(values[index] > num){
num = values[index];
}
}
cout << " Largest value in array is " << num << endl;
}

/*Function to display the smallest value*/
void displaySmallestValue(int values[]){
int num = values[0];
for(int index = 0; index < SIZE; index++){
if(values[index] < num){
num = values[0];
}
}

cout << " Smallest value in array is " << num << endl;
}

Sample output:

Enter a number: 10   

All larger value(s)than10:
91   
All Smaller value(s)than10:   
91   
9
1
90   
98   
53   
22   
76   
29   
37   
65   

Largest value in array is 9   
Smallest value in array is 9

please rate the solution, your rating is precious ;)

Add a comment
Know the answer?
Add Answer to:
#include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void...
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
ADVERTISEMENT