Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What is not right with this code? I added temperature to the original and it will not run correctly now. 4. Prepare a new test

What is not right with this code? I added temperature to the original and it will not run correctly now.

4. Prepare a new test table with at least 2 distinct test cases listing input and expected output for the new code you created allowing the user to enter another meteorological element.

#define NUMMONTHS 12 #define NUMYEARS 5 #include // function prototypes void inputdata(); void printdata(); // Global variables // These are available to all functions float Raindata[NUMYEARS][NUMMONTHS]; float WindSpeed[NUMYEARS][NUMMONTHS]; float Temperature[NUMYEARS][NUMMONTHS]; char years[NUMYEARS][5] = {"2011","2012","2013","2014","2015"}; char months[NUMMONTHS][12] ={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; int main () { char enterData = 'y'; printf("Do you want to input Precipatation data? (y for yes) "); scanf("%c",&enterData); if (enterData == 'y') { // Call Function to Input data inputdata(); // Call Function to display data printdata(); } else { printf("No data was input at this time "); } printf("Please try the Precipitation program again. "); return 0; } // function to inputdata void inputdata() { /* variable definition: */ float Rain=1.0; float Wind=1.0; float Temperature=1.0; // Input Data for (int year=0;year < NUMYEARS; year++) { for (int month=0; month< NUMMONTHS; month++) { printf("Enter rain for %d, %d: ", year+1, month+1); scanf("%f",&Rain); Raindata[year][month]=Rain; } }

for (int year=0;year < NUMYEARS; year++) { for (int month=0; month< NUMMONTHS; month++) { printf("Enter WindSpeed for %d, %d:(mph) ", year+1, month+1); scanf("%f",&Wind); WindSpeed[year][month]=Wind; } }

for (int year=0;year < NUMYEARS; year++) { for (int month=0; month< NUMMONTHS; month++) { printf("Enter Temperature for %d, %d:(degrees) ", year+1, month+1); scanf("%f",&Temperature); Temperature[year][month]=Temperature; } } } // Function to printdata void printdata(){ // Print data printf ("year\t month\t rain\t wind "); for (int year=0;year < NUMYEARS; year++) { for (int month=0; month< NUMMONTHS; month++) { printf("%s\t %s\t %5.2f\t %5.2f ", years[year],months[month],Raindata[year][month],WindSpeed[year][month]); } } printf ("sum the rainfall for each year "); printf ("year\t rain(sum) "); float sumRain = 0.0; for (int year=0;year < NUMYEARS; year++) { for (int month=0; month< NUMMONTHS; month++) { sumRain += Raindata[year][month]; } printf("%s\t %5.2f ", years[year],sumRain); }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions