#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.
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 ;)
#include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void...
#include <iostream> using namespace std; int main(void) { int SIZE; cout<<"Enter the size of the array"<<endl; cin>>SIZE; int *numlist = new int[SIZE]; // Read SIZE integers from the keyboard for (int i = 0; i<SIZE; i++ ) { cout << "Enter value #" << i+1 << ": "; cin >> numlist[i]; } // Display the numbers in a reverse order for (int i = SIZE; i > 0; i--...
One dimensional array What this code print #include <iostream> using namespace std; int main () { const int SIZE = 7; int numbers [SIZE] = {1, 2, 4, 8): // Initialize first 4 elements cout << Here are the contents of the array:\n"; for (int index = 0; index < SIZE: index++} cout << numbers[index] << ; cout << endl; return 0; }
// PLACE YOUR NAME HERE #include <iostream> using namespace std; float findAverage (int [], int); // finds average of all //grades int findHighest (int [], int); // finds highest of all //grades int findFirstFail( int[]); int main() { int grades[100]; // the array holding 100 grades. int numberOfGrades; // the number of grades read. int pos; // index to the array. float avgOfGrades; // contains the average of the grades. int highestGrade; // contains the highest grade. int inderOfFail; //...
#include <iostream> #include <fstream> using namespace std; //constants const int CAP = 100; //function prototypes bool openFile(ifstream &); void readData(ifstream &, int [], int &); void printData(const int [], int); void sum(const int[], int); void removeItem(int[], int &, int); int main() { ifstream inFile; int list[CAP], size = 0; if (!openFile(inFile)) { cout << "Program terminating!! File not found!" << endl; return -1; } //read the data from the file readData(inFile, list, size); inFile.close(); cout << "Data in file:" <<...
#include <iostream> #include <vector> #include <iomanip> using namespace std; int main() { const int NUM_ITEMS = 8; vector <double> inverse(NUM_ITEMS); int j; double temp; for (int i = 0; i < NUM_ITEMS; i++) { inverse.at(i) = 1 / (i + 1.0); } cout << fixed << setprecision(2); cout << "Original vector..." << endl; for (int i = 0; i < NUM_ITEMS; i++) { cout << inverse.at(i) << " "; } cout << endl; cout << "Reversed vector..." << endl; for...
Write the missing statements for the following program. #include <iostream> using namespace std; int main(void) { int Num1; cout << "Enter 2 numbers: "; cin >> Num2; if (Num1 < Num2) cout << "Smallest number is " << Num1; else cout << "Smallest number is " << Num2; return 0; }
#include "stdafx.h" #include <iostream> using namespace std; class dateType { private: int dmonth; int dday; int dyear; public: void setdate (int month, int day, int year); int getday()const; int getmonth()const; int getyear()const; int printdate()const; bool isleapyear(int year); dateType (int month=0, int day=0, int year=0); }; void dateType::setdate(int month, int day, int year) { int numofdays; if (year<=2008) { dyear=year;...
#include <iostream> using namespace std; int * newZeroArray(int size) { //your code here } int main() { int size = 10; int * A = newZeroArray(size); for(int i = 0; i < size; i++) cout << A[i] << " "; cout << endl; }Write a function that takes a size, creates a new array of that size with all zeros, and returns the array. If the size is not a valid size for an array, do not return a valid...
howthe output of the following 4 program segments (a) const int SIZE=8; int values[SIZE] = {10, 10, 14, 16, 6, 25, 5, 8}; int index; index=0; res = values[index]; for (int j=1; j<SIZE; j++) { if (values[j] > res) { res = values[j]; index = j; cout << index << res << endl; } } cout <<...
#include <iostream> #include <sstream> #include <string> using namespace std; int main() { const int index = 5; int head = 0; string s[index]; int flag = 1; int choice; while (flag) { cout << "\n1. Add an Item in the Chores List."; cout << "\n2. How many Chores are in the list."; cout << "\n3. Show the list of Chores."; cout << "\n4. Delete an...