Question

Design a program that lets the user enter the total rainfall for each of 12 months...

Design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amount.

PLEASE MODULARIZED THE CODE  

PLEASE USE C PROGRAMMING AND ADD PSEUDOCODE

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

CODE:

// including stdio library
#include <stdio.h>
float total_rainfall(float a[]);
int get_max(float *a);
int get_min(float *a);
//Main function
int main () {
// declaring array with size 12 to store rainfall values of 12 months
float arr[12],total=0,min,max;
int max_index,min_index;
// loop to input values from user to the array
for (int i = 0; i < 12; i++)
{
printf("Enter Total Rainfall for Month %d : ",i+1);
scanf("%f",&arr[i]);
}
//calling functio to get total rainfall
total = total_rainfall(arr);
// calling function to get maximum rainfall month
max_index = get_max(arr);
max = arr[max_index];
// calling function to get minimum rainfall month
min_index = get_min(arr);
min = arr[min_index];
//print total rainfall
printf("Total Rainfall for the year : %f\n",total);
// printing average monthly rainfall for 12 months
printf("The Average Monthly Rainfall : %f\n",total/12 );
// printing highest rainfall value and the month
printf("Month with Highest Rainfall %f is : Month %d\n",max,max_index+1);
// printing lowest rainfall value and the month
printf("Month with Lowest Rainfall %f is : Month %d\n",min,min_index+1);
}
// function to get total rainfall
float total_rainfall(float *a){
float total=0;
// Loop to calculate total rainfall of the year
for (int i = 0; i < 12; i++)
{
total = total + a[i];
}
return total;
}
// function for getting maximum month index
int get_max(float *a){
//Initially assume maximum value as first element and then check for remaining elements
// whether any element greater than this element or not
int max_month = 0;
// loop calculate maximum rainfall
for (int i = 1; i < 12; i++)
{
// if any element is maximum than current max value..
if(a[i]>a[max_month]){
// store which month have minimum rainfall
max_month = i;
}
}
return max_month;
}
// function for getting minimum month index
int get_min(float *a){
//Initially assume minimum value as first element and then check for remaining elements
// whether any element lesser than this element or not
int min_month = 0;
for (int i = 1; i < 12; i++)
{
// if any element is minimum than current min value..
if(a[i]<a[min_month]){
// store which month have minimum rainfall
min_month = i;
}
}
return min_month;
}

CODE SCREENSHOTS:
OUTPUT:

PSEUDOCODE:

//This program calculate and display
//the total rainfall for the year,
//the average monthly rainfall,
//and the months with the highest and lowest amount.

take an array of size 12
intially i is 0
for i less than 12{
   prompt "Enter rainfall value for month i"
   }

//Calculate total rainfall

set total to 0;
for every element in array{
   add array element total value
}

//Calculate maximum rainfall month

intitially set max_index to array first element index
for each element in array{
   if element in array greater than max index element
          and store month number as max index element
}

//Calculate minimum rainfall month

intitially set min_index to array first element
for each element in array{
   if element in array lesser than min index element
          and store month number as min element

diplay total rainfall value
display average rainfall by dividing total rainfall with 12
display maximum monthly rainfall month and the month
display minimum monthly rainfall month and the month

Please Don't Forget to UPVOTE my solution and Comment if you have any doubts.  I will definitely answer

Add a comment
Know the answer?
Add Answer to:
Design a program that lets the user enter the total rainfall for each of 12 months...
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
  • Write a program in C++ that lets the user enter the total rainfall for each of...

    Write a program in C++ that lets the user enter the total rainfall for each of 12 months into an array of doubles. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Input validation: Do not accept negative numbers for monthly rainfall figures.

  • The Problem Design a program that lets the user enter the total rainfall for each of...

    The Problem Design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, the number of months above and below the average rainfall, and the highest rainfall for each quarter of the year. The Assignment Write a Java program that contains five method/functions as follows: main(). Calls the functions enterRain, rainStats, aboveBelow, and quarterlyRain. enterRain(). Uses...

  • Rainfall Statistics Write a program that lets the user enter the total rainfall for each of...

    Rainfall Statistics Write a program that lets the user enter the total rainfall for each of 12 months (starting with January) into an array of doubles. The program should calculate and display (in this order): the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Months should be expressed as English names for months in the Gregorian calendar, i.e.: January, February, March, April, May, June, July, August, September, October, November, December....

  • pseudocode and Python Repl.it :Recall that Programming Exercise 3 in Chapter 8 asked you to design...

    pseudocode and Python Repl.it :Recall that Programming Exercise 3 in Chapter 8 asked you to design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Enhance the program so it sorts the array in ascending order and displays the values it contains.

  • Design a program that asks the user to enter a series of 20 numbers. The program...

    Design a program that asks the user to enter a series of 20 numbers. The program should store the numbers in the array and then display the following data: The lowest number in the array The highest number in the array The total of the number in the array The average of the numbers in the array PLEASE GIVE THE PSEUDOCODE AND CODE IN C PROGRAMMING

  • Write a program that scores the total rainfall for each of 12 months into an array...

    Write a program that scores the total rainfall for each of 12 months into an array double. A sample array definition is shown below double thisYear[] = {1.6, 2.1, 1.7, 3.5, 2.6, 3.7, 3.9, 2.6, 2.9, 4.3, 2.4, 3.7}; The program should have the four functions to calculate the following 1. The total rainfall for the year 2. The average monthly rainfall 3. The month with most rain 4. The month with least rain Output: What to deliver? Your .cpp...

  • Write a Python program that allows the user to enter the total rainfall for each of...

    Write a Python program that allows the user to enter the total rainfall for each of 12 months into a list. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest rainfall amounts. Data: January: 8.9 inches February: 11.1 inches March: 13.4 inches April: 6.9 inches May: 8.7 inches June: 9.1 inches July: 15.9 inches August: 4.4 inches September: 3.1 inches October: 5.6 inches November: 7.8...

  • qbasic is the programming language Chapter 8 Do Programming Exercise 8-3 om page 414. Create a...

    qbasic is the programming language Chapter 8 Do Programming Exercise 8-3 om page 414. Create a string array to hold the months of the year. Call it anything you want to just make sure it's a string array is at the end of the name, e.g. months). Create a DATA statement that holds the month names: DATA "jan","Feb", "Mar" etc. Next you'll need a FOR loop to READ the DATA into the array, Call a SUB to get the rainfall...

  • Write a C++ console application that allows your user to capture rainfall statistics. Your program should...

    Write a C++ console application that allows your user to capture rainfall statistics. Your program should contain an array of 12 doubles for the rainfall values as well as a parallel array containing the names of the months. Using each of the month names, prompt your user for the total rainfall for that month. The program should validate user input by guarding against rainfall values that are less than zero. After all 12 entries have been made, the program should...

  • Total Sales Design a program that asks the user to enter a store’s sales for each...

    Total Sales Design a program that asks the user to enter a store’s sales for each day of the week. The amounts should be stored in an array. Use a loop to calculate the total sales for the week and display the result. Need: variable lists, IPO Chart, pseudocode, Flowchart, and working Python code. 2. Lottery Number Generator Design a program that generates a 7-digit lottery number. The program should have an Integer array with 7 elements. Write a loop...

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