1. Engineering
  2. Computer Science
  3. problem redo the c program you wrote to use the...

Question: problem redo the c program you wrote to use the...

Question details

PROBLEM: Re-do the C program you wrote to use the following functions. Fix any problems you had with the original program. Produce the EXACT output shown at the end of the document.

  1. Generate a graph that compares, on a month-by-month basis, the monthly rainfall for Kamloops for the first half of 2018 (i.e. Jan – June) versus the normal (30 year average) rainfall for Kamloops for the same months.

  1. Create and call a function to return the month name to main()
  1. Create and call ONE function to print one line of symbols.
    • call it the first time to print the line of *
    • call it a second time to print the line of !
    • no if statement is needed or allowed in this function
    • Think very carefully about the parameter list for this function

  1. Call a function to print the scale and the legend as shown below.
  1. Call a function to find and print the total rainfall for each data set, and also the comparison of the two totals. The function will state whether 2018 was wetter, drier, or equal to a normal 6 month rainfall and by how much.
  1. Call a function to determine which month in 2018 had the highest rainfall, and print the month name (using the function described in #2), the rainfall amount and how that amount compares to the normal amount for that month.

Input will consist of 6 pairs of numbers representing the normal rainfall for the month and the 2018 rainfall amount for the same month. Use the exact data shown below when you run your program, (Note: the data and output below are for illustration purposes only. Your program must be able to work with any data that has this format)

#include "stdafx.h"

int main(){

//Variables for total rain falls

double normal, rain2018;

//Rainfalls stored arrays

double monthRainFall[] = { 3.1,4.7,4.2,5.0,4.0,6.3 };

double rainAmt2018[] = { 5.4,4.4,4.1,6.0,5.6,4.5 };

char month[6][10]{ "January","February","March","April","May","June" };

double total = 0;

double total1 = 0;

int s = 6;


printf("Rainfall comparison for January to June 2018 \n");

//Loop to display graph

for (int i = 0; i < s; i++) {

printf("\n%8s %c ", month + i, '|');

printf("%10c", '|');

for (double j = 0; j <= monthRainFall[i]; j += .2) {

printf("%c", '*');


printf(" ");

printf("\n%21c", '|');

for (double j = 0; j <= rainAmt2018[i]; j += .2) {

printf("%c", '!');


printf(" ");


//Display legend section

printf_s("\n%-20s|----1----2----3---4----5----6----7----8 ", "Scale:");

printf("\n\nLegend\n * - normal rainfall for a given month \n ! - 2018 rainfall for a given month\n");

//find total normal rainfall

for (int i = 0; i < s; i++) {

total += monthRainFall[i];


//find total 2018 rainfall

for (int i = 0; i < s; i++) {

total1 += rainAmt2018[i];


int counter = 0, highestmonth;

float highest = 0;

float highestsecond = 0;

while (counter < 6)


if (highest < rainAmt2018[counter]){

highest = rainAmt2018[counter];

highestmonth = counter;


counter = counter + 1;


highestsecond = monthRainFall[highestmonth];

//Display the detail of the total normal rainfall and 2018

printf("Total normal rainfall was %.2lf mm. \n", total);

printf("Total rainfall for 2018 was %.2lf mm. \n", total1);

printf("The month with the highest rainfall was %s at %.1f mm\n", month[highestmonth], highest);

printf_s("Compared to the 30 year average for %s is %.1fmm.\n", month[highestmonth], highestsecond);

//find wetter or drier year of 2018 compared to the normal

double diff = highest - highestsecond;

if (diff < 0) {

printf("2018 was a drier year than normal by %.2lf mm. \n", (-1 * diff));


else {

printf("2018 was a wetter year than normal by %.2lf mm. \n", diff);



Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution