I'm a college student very new to programming. I'm having some troubles with this specific program.
The program should be able to store 500 integer values (temperatures) in a global array. The program has to contain the specific functions:
- A function that finds the average of all temperatures stored
- A function that finds the average of the last 5 recorded temperatures. If there are less than 5 temperatures recorded, return the average of all recorded temperatures.
- A function that records a new temperature. It must check if there is still space in the array.
- A function that prints the number of temperatures recorded
- A function that prints all the temperatures recorded
Here is my current program. I only need help writing ONE of the functions. I want to learn how to write and call them myself with some guidance. Thanks all.
Code:#include <stdio.h> #define maxsz 500 int temp[maxsz]; float avgtemp () { } float avgtemp5() { } int addtemp () { } int numtemp() { } int alltemp() { } int main(void) { char option; printf("Please select an option:\n"); printf("(A) Computed average of all temperatures\n"); printf("(B) Compute the average of the last five temperatures\n"); printf("(C) Add new Temperatures\n"); printf("(D) Print the number of temperatures recorded\n"); printf("(E) Print the temperatures recorded\n"); printf("(F) Exit the program\n"); scanf(" %c", &option); switch (option) { case 'A': avgtemp(); case 'B': avgtemp5(); case 'C': addtemp(); case 'D': numtemp(); case 'E': alltemp(); case 'F': return 0; } return 0; }