Question

In: Computer Science

Program IN C Prompt the user to enter month number and year. Retain an appropriate response...

Program IN C

Prompt the user to enter month number and year. Retain an appropriate response for invalid month numbers, but don’t worry about validity of year.

2.Determine the number of days in the month entered (ignore leap years).

3.Use the answer to step 2 in one FOR-LOOP to ask the user to enter a FAHRENHEIT temperature (integer or floating) for each day of the month utilizing a prompt that includes the DATE.

a. Prompt the user to enter the Fahrenheit temperature for 2/1/2018... etc b.Continue to prompt the user for the Fahrenheit temperature for EACH day of the month entered until the loop reaches the last day of that month, e.g. 2/28/2018, last day of Feb.

4.When all daily temps have been entered, display month number, and average temperature in Fahrenheit and Celsius. (You know or can find the conversion equation.)

Display averages to nearest tenth of degree.

5.When TESTING your program and demonstrating it to your instruct or, let each month have 21 fewer days, 7, 9 or 10 instead of 28, 30 or 31.Appropriate comments and messages to user are required

.

Solutions

Expert Solution

The snapshot the required C program is as below:-

//Output

Attaching the text of the C code, in snapshot of the code above the last printf statement didn't came clearly, the ending part were cut, you can refer the below code for clarity:-

#include<stdio.h>
int main()
{
   //variable declaration
   int month_number=0;
   int year=0;
   int no_of_days=0;
   int i=0;
   float tempF[31]; //temperature array for storing fahrenheit values
   float sumTempF=0;//sum of fahrenheit temperature
   float avg_Fahrenheit_temp=0;//average fahrenheit temparature
   float avg_Celsius_temp=0;//average celsius temparature ->calculated using conversion formula
  
   //prompt user to enter month
   while(1) //infinite loop to prompt user again in case invalid month is entered
   {
  
   printf("Enter Month Number\n");
   scanf("%d",&month_number);
  
   if(month_number<1 || month_number>12) //month is invalid
   {
       printf("Invalid Month!\n");
       continue;
   }
   else
   {
       break;
   }
  
   }
   //prompt user to enter year
   printf("Enter Year\n");
   scanf("%d",&year);
  
   //Determine number of days in the month
  
   switch(month_number)
   {
       case 1:
           no_of_days=31; //Jan
           break;
          
       case 2:
           no_of_days=28; //Feb
           break;
      
       case 3:
           no_of_days=31; //Mar
           break;
      
       case 4:
           no_of_days=30; //Apr
           break;

       case 5:
           no_of_days=31; //May
           break;
      
       case 6:
           no_of_days=30; //Jun
           break;  
          
       case 7:
           no_of_days=31; //Jul
           break;
      
       case 8:
           no_of_days=31; //Aug
           break;
      
       case 9:
           no_of_days=30; //Sep
           break;
      
       case 10:
           no_of_days=31; //Oct
           break;
      
       case 11:
           no_of_days=30; //Nov
           break;
      
       case 12:
           no_of_days=31; //Dec
           break;
      
   }
  
   //for loop for taking input of temperatures of days in the given moth from user
  
   //reducing days by 21 as asked in question
   no_of_days=no_of_days-21; //you can comment this line if you want to enter actual days of 28,30,31
  
   for(i=1;i<=no_of_days;i++)
   {
       printf("Enter FAHRENHEIT temperature for %d/%d/%d\n",month_number,i,year);
      
       //as array starts from 0 we take index as i-1 since i=1 initially, i-1=0, you can take separate variable also
       //but for reusability i have used i itself
      
       scanf("%f",&tempF[i-1]);
          
       //calculating sum of fahrenheit temperature
      
       sumTempF=sumTempF+tempF[i-1];
          
      
   }//for close
  
   avg_Fahrenheit_temp=sumTempF/no_of_days;
  
   //conversion formula fahrenheit to celsius
   // c/5=(f-32)/9
   avg_Celsius_temp=(5.0)*((avg_Fahrenheit_temp-32)/9.0);  
  
   //"%.1f" is used to round degrees upto tenth of a degree i.e upto 1 decimal place
   printf("Month Number = %d \t Average Temperature in Fahrenheit = %.1f \t Average Temperature in Celsius = %.1f",month_number,avg_Fahrenheit_temp,avg_Celsius_temp);
  
   return 0;
}


Related Solutions

IN C This assignment is to write a program that will prompt the user to enter...
IN C This assignment is to write a program that will prompt the user to enter a character, e.g., a percent sign (%), and then the number of percent signs (%) they want on a line. Your program should first read a character from the keyboard, excluding whitespaces; and then print a message indicating that the number must be in the range 1 to 79 (including both ends) if the user enters a number outside of that range. Your program...
The program will prompt the user to enter a number between [10 .. 20] (inclusive). After...
The program will prompt the user to enter a number between [10 .. 20] (inclusive). After verifying that the number is within the proper range, you will generate that many random numbers and place them into a dynamically allocated array. Your program will then display the contents of the array (with 4 numbers per line). Next, you will sort the values in descending order (from largest to smallest). Lastly, you will display the sorted numbers (again, with 4 per line)....
Write a C program that prompt the user to enter 10 numbers andstores the numbers...
Write a C program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
Write a C++ program that prompt the user to enter 10 numbers andstores the numbers...
Write a C++ program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
JAVA Write a java program that will sum all positive number. Prompt the user to enter...
JAVA Write a java program that will sum all positive number. Prompt the user to enter numbers and add all positive numbers. The program will not add negative numbers and the program will stop when you enter ‘0’.   Enter a number> 25 Enter a number> 9 Enter a number> 5 Enter a number> -3 Enter a number> 0 Sum = 39
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream>, switch and if-else statements only and do not use string storing for the conversion in words. Thank you.** **Our class is still discussing on the basics of programming. Please focus only on the basics. Thank you.** Example outputs: Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four...
Prompt the user to enter an integer Then, prompt the user to enter a positive integer...
Prompt the user to enter an integer Then, prompt the user to enter a positive integer n2. Print out all the numbers that are entered after the last occurrence of n1 and whether each one is even or odd If n1 does not occur or there are no values after the last occurrence of n1, print out the message as indicated in the sample runs below. Sample: Enter n1: -2 Enter n2: 7 Enter 7 values: -2 3 3 -2...
Create in Java a program that will prompt the user to enter aweight for a...
Create in Java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates both bolus and infusion rates based on weight of patient in an interactive GUI application, label it AMI Calculator. The patients weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the...
Create in java a program that will prompt the user to enter a weight for a...
Create in java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates infusion rates based on weight of patient in an interactive GUI application, label it HEPCALC. The patients’ weight will be the only entry from the user. To calculate the infusion rate you will multiply 12 times the weight divided by 50 for a total number. The end result will need to round up or down the whole number....
IN C++ Write a program that prompts the user to enter the number of students and...
IN C++ Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score (display the student’s name and score). Also calculate the average score and indicate by how much the highest score differs from the average. Use a while loop. Sample Output Please enter the number of students: 4 Enter the student name: Ben Simmons Enter the score: 70 Enter the student name:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT