Create a Raptor flowchart to accept 12 monthly rainfall amounts from the user an
ID: 3587838 • Letter: C
Question
Create a Raptor flowchart to accept 12 monthly rainfall amounts from the user and calculate the total, largest and smallest monthly rainfall amounts, and the average amount. All calculations, except average, should be inside the loop accepting rainfall amount from the user. No sub-procedures are needed for this assignment. Display the total, the average, the largest monthly amount and the smallest monthly amount. Use a parallel array (see page 317) for the month number corresponding to the rainfall amount. Initialize it to the values 1 through 12.
Explanation / Answer
/*************************************************************************************
* Header files and macro declaration
*************************************************************************************/
#include<stdio.h>
#include<stdlib.h>
#define TOTAL_MONTHS 12
/**************************************************************************************
* Name :
* main()
* Purpose :
* To accept 12 monthly rainfall amounts from the user.
* Calculate the total, largest and smallest monthly rainfall amounts, and the average amount.
*
***************************************************************************************/
int main() {
double largest,smallest,total=0,avg=0,months[TOTAL_MONTHS],amount;
int i;
for(i=1;i<=TOTAL_MONTHS;i++)
{
printf(" Please enter rainfall amount of month %d : ",i);
scanf("%lf",&amount);
months[i] = amount;
total += amount;
if(i==1)
{
largest = months[i];
smallest = months[i];
}
else {
if(largest < amount)
largest = amount;
if(smallest > amount)
smallest = amount;
}
}
avg = total/TOTAL_MONTHS;
printf(" Largest monthly rainfall amount is %lf ",largest);
printf(" Smallest monthly rainfall amount is %lf ",smallest);
printf(" Total monthly rainfall amount is %lf ",total);
printf(" Average monthly rainfall amount is %lf ",avg);
return 0;
}