1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <iostream>
#include <cmath>
#include <string>
void getArray(int tempArr[], int arrSize);
void printArray(int tempArr[], int arrSize);
int calculateHighestArray(int tempArr[],int arrSize);
int calculateLowestArray(int tempArr[],int arrSize);
int main(){
int people, min, max;
std::cout << "Enter the number of people " << std::endl;
std::cin >> people;
int pancakes[people];
std::cout << "Enter the number of pancakes for the " << people << " people." << std::endl;
getArray(pancakes, people);
printArray(pancakes, people);
max = calculateHighestArray(pancakes, people);
std::cout << "The highest number of pancakes ate was " << max << std::endl;
min = calculateLowestArray(pancakes, people);
std::cout << "The lowest number of pancakes ate was " << min << std::endl;
}
//The below functions deal with input and output from arrays. All output of array functions print to console.
void getArray(int tempArr[], int arrSize){
for(int i = 0;i < arrSize;i++){
std::cin >> tempArr[i];
}
}
void printArray(int tempArr[], int arrSize){
for(int i = 0;i < arrSize;i++){
std::cout << "Person " << i+1 << ": " << std::endl;
std::cout << tempArr[i] << std::endl;
}
}
int calculateHighestArray(int tempArr[],int arrSize){
int maxValue = tempArr[0];
for(int i=1;i<arrSize;i++){
if(tempArr[i] > maxValue){
maxValue = tempArr[i];
}
}
return maxValue;
}
int calculateLowestArray(int tempArr[],int arrSize){
int minValue = tempArr[0];
for(int i=1;i<arrSize;i++){
if(tempArr[i] < minValue){
minValue = tempArr[i];
}
}
return minValue;
}
|