Reference no: EM13166064
Need a prg that lets user enter total rainfall for each of 12 months into an array of doubles,prg should then calculate and display total rainfall for year,the average monthly rainfall, and the months with highest and lowest amounts
need to use four functions
double getTotal(double[],int);//calculates adn returns total of the values stored in the array parameter;the size parameter indicates the number of elements in the array
double getAverage(doube[],int); //returns the average of the values in the array parameter;the size parameter indicates the number of elements in the array
double getLargest(double[],int,int &);//returns the smallest value in the array parameter and stores the subscript of the largest value in the element reference parameter
double getSmallest(double[],int,int &);//returns the smallest value in the array parameter and stores the subscript of the smallest value in the element reference parameter
this is what i have but im struggling with arrays and functions please help i know its wrong but i dont know what to fix or even if im on right track
#include<iostream>
#include<string>
using namespace std;
double getTotal(double array[],int monthTotalRain)
{
string months[]={"January","February","March","April","May","June","July","August","September",
"October","November","December"};
double monthTotalRain[12];
double totalRainFall=0;
for(int count=0;count<=11;count++)
{
cout<<"What is total rainfall for every month? "<<endl;
cout<<months[count];
cin>>monthTotalRain[count];
totalRainFall+=monthTotalRain;
}
while monthTotalRain<0)
{
cout<<"Please re-enter amount above zero: ";
cin>>monthTotalRain;
totalRainFall+=monthTotalRain;
}
cout<<"The total amount of rainfall for the year is: "<<totalRainFall<<endl;
return totalRainFall;
}
double getAverage(double array[],int size)
{
double average;
average=getTotal[]/size;
return average;
}
double getLargest(double array[],int size,int &largest)
{
double highest;
highest=array[0];
for(int count=0;count<size;count++)
{
if array[count]>highest)
highest=array[count];
}
return highest;
double getSmallest(double array[],int size,int &smallest)
{
double lowest;
lowest=array[0];
for(int count=1;count<size;count++)
{
if array[count]<lowest)
lowest=array[count];
}
return lowest;
}
int main()
{
const int rain=12;
double rainfall[rain];
double totalRainYr=0;
double averageRain;
string highMonth;
string lowMonth;
double highestRain;
double highest=0;
double lowest=0;
double lowestRain;
double total;
double average;
total=getTotal(rainfall,rain);
average=getAverage(rainfall,rain);
highestRain=getLargest(rainfall,rain,highest);
lowestRain= getSmallest(rainfall,rain,lowest);
cout<<"The lowest amount of rain is "<<lowestRain<<endl;
cout<<"The highest amount of rain is "<<highestRain<<endl;
return 0;
}
State equilibrium ph value of rainwater if atmospheric
: What would be the equilibrium pH value of rainwater if atmospheric SO2 gas were its only dissolved constituent? Assume that the fugacity (activity) of SO2 gas in the atmosphere is 5 x 10-9 bar
|
Relocation hardware costs money
: Since relocation hardware costs money, why support relocation? Give at least two reasons? 2) Make arguments for smaller page size on a paging system?
|
Lives and legacies of the pharaohs hatshepsut
: Consider the lives and legacies of the pharaohs Hatshepsut, Akhenaten, and Tutankhamen. If you had to choose, which of these pharaohs would you prefer to be and why?
|
Acquire from a reference work the solubility of silver
: Obtain from a reference work the solubility of silver acetate at 20 degree C. Usually this will be reported in units of grams per 100 mL of water
|
Need a prg that lets user enter total rainfal
: Need a prg that lets user enter total rainfall for each of 12 months into an array of doubles,prg should then calculate and display total rainfall for year,the average monthly rainfall, and the months with highest and lowest amounts
|
Design a nine-step counter to count using d flip-flops
: Design a nine-step counter to count in the following sequence using D flip-flops (TTL 74704) on a breadboard and on verilog: 0011, 0101, 1001, 1000, 1011, 1010, 0110, 0100, 0111, 0011, ... Include in the design a means for resetting the counter to 00..
|
Law code of hammurabi and laws today
: Identify and describe specific differences you notice between the Law Code of Hammurabi and laws today.
|
You are to design and construct a 3-bit synchronous counter
: You are to design and construct a 3-bit synchronous counter with an enable (EN) input. The counter is to count in the prescribed squence shown below if EN is true at the next active clock transition
|
Write a program to clean up lane9.dat
: Write a program to clean up lane9.dat. Write all numbers and spaces to cleanlane9.txt.
|