Question

In: Computer Science

-In C Programming- Write a program to display the total rainfall for a year. In addition,...

-In C Programming-

Write a program to display the total rainfall for a year. In addition, display the average monthly rainfall, and the months with the lowest and highest rainfall.

Create an array to hold the rainfall values. Create a 2nd parallel array (as a constant) to hold the abbreviated names of the months. I created my arrays to be 1 element bigger than needed, and then disregarded element [0] (so that my months went from [1] = "Jan" to [12] = "Dec").

Populate the array with the rainfall values entered by the user. Then, display the rainfall values. Display the 1st 6 months, followed by the last 6 months Then display the statistics (the total, average, lowest, and highest rainfall).

Calculate the total rainfall. After you get the total, you should be able to calculate the average (use the size (minus 1 if the array was 1 element bigger than needed) of the array). Then find the index of lowest rainfall and the index of highest rainfall. Finally, display the statistics, using the indexes that were found to get the lowest and highest rainfall value and the name of the month from the arrays.

Format the output to 1 decimal place.

There is no validation.

Solutions

Expert Solution

Program:

#include<stdio.h>

int main()
{
int i,lowest=0,highest=0;
double values[12];
double min,max;
double total=0.0,average;

const char *month[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};

printf("\nEnter Rainfall of each of 12 months: \n");

for(i=0;i<=11;i++)
{
scanf("%lf",&values[i]);
}

max=values[0];
min=values[0];

printf("\nMonth and its rainfall value: \n\n");
for(i=0;i<=11;i++)
{
printf("%s : %.2lf\n",month[i],values[i]);
if(max<values[i])
{
max=values[i];
highest=i;
}
if(min>values[i])
{
min=values[i];
lowest=i;
}
total=total+values[i];
}

average=total/12;


printf("\nTotal rainfall for the year : %.1lf\n",total);
printf("\n\nThe average monthly rainfall : %.1lf\n",average);
printf("\n\nThe month %s with the highest rain ie %.1lf\n",month[highest],max);
printf("\n\nThe month %s with the lowest rain ie %.1lf\n",month[lowest],min);

return 0;
}

Output:


Related Solutions

Write a C++ program that lets the user enter the total rainfall for each of 12...
Write a C++ 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,...
Write a C++ program to display toy name
Write a C++ program to display toy name
write pseudocode not c program If- else programming exercises 1.    Write a C program to find...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find maximum between two numbers. 2.    Write a C program to find maximum between three numbers. 3.    Write a C program to check whether a number is negative, positive or zero. 4.    Write a C program to check whether a number is divisible by 5 and 11 or not. 5.    Write a C program to check whether a number is even or odd. 6.    Write...
In Object Oriented programming C++ : Write the appropriate functions for Student to neatly display a...
In Object Oriented programming C++ : Write the appropriate functions for Student to neatly display a Student, and then finally GPA. Have items neatly line up in columns. I need help creating a derived class called student that finds GPA (between 0.0 and 4.0) and credits completed (between 0 and 199).
Using c++, write a program that will display your name as a void function then will...
Using c++, write a program that will display your name as a void function then will perform the following by user-defined functions: a. to compute for the sum of two numbers (n1, n2) using function.
Programming in C++ Write a program that prints the values in an array and the addresses...
Programming in C++ Write a program that prints the values in an array and the addresses of the array’s elements using four different techniques, as follows: Array index notation using array name Pointer/offset notation using array name Array index notation using a pointer Pointer/offset notation using a pointer Learning Objectives In this assignment, you will: Use functions with array and pointer arguments Use indexing and offset notations to access arrays Requirements Your code must use these eight functions, using these...
Write a C++ console application that allows your user to enter the total rainfall for each...
Write a C++ console application that allows your user to enter the total rainfall for each of 12 months into an array of doubles. 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 calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest rainfall amounts.
Write a C++ program that uses nested loops to collect data and calculate the average rainfall...
Write a C++ program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask the user for the number of years. The outer loop will iterate once for each year. The inner loop will iterate 12 times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations, the program should display the number...
C PROGRAMMING – Steganography In this assignment, you will write an C program that includes processing...
C PROGRAMMING – Steganography In this assignment, you will write an C program that includes processing input, using control structures, and bitwise operations. The input for your program will be a text file containing a large amount of English. Your program must extract the “secret message” from the input file. The message is hidden inside the file using the following scheme. The message is hidden in binary notation, as a sequence of 0’s and 1’s. Each block of 8-bits is...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user to enter the three examinations ( test 1, test 2, and test 3), homework, and final project grades then calculate and display the overall grade along with a message, using the selection structure (if/else). The message is based on the following criteria: “Excellent” if the overall grade is 90 or more. “Good” if the overall grade is between 80 and 90 ( not including...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT