Hey all ! I am new to this forum and would need to get some help in my program !
I am trying to write a program that displays a menu for the user to choose which rainfall data to display from January to March. One of the options would be to display the total rainfall of the month, which is the adding of all the rainfall in MM for each day. Part of my code is as shown below, however i am unable to get the program to add up the data in my array correctly as it displays weird numbers and not the one that i need
externfloat rainfallJan[];
externfloat rainfallFeb[];
externfloat rainfallMar[];
externvoid getPwd(char* pwd); // function prototype to store password input
externint chkPwd(char* pwd);
#include <stdio.h>
void SystemLogin(void);
void rainfallMenu(void);
void main(void)
{
char userinput;
int j;
float total;
char systemPwd[]="abc123"; // declare system password as global string variable
total=0.0;
SystemLogin(); // Call in function for logging into the system
do
{
rainfallMenu();//call function to display menu
userinput=getchar(); // Record user input with getchar() function
fflush(stdin); //remove remaining input stream data
switch(userinput)
{
case'A': case'a':
printf("The raifall data for January; is :\n");
for ( j=0;j<31;j++ )
{
total = total + rainfallJan[j];
printf("%.2f", total);
}
printf("\n\n");
printf("View more rainfall data or quit from the following options :\n");
printf("\n\n");
break;
The following code below is my data for the rainfall data of January in a seperate file
The following code below is my data for the rainfall data of January in a seperate file
I wonder if you are misinterpreting how rainfall data is supposed to be represented in a separate file. I doubt that the separate file is supposed to be some other code file that gets compiled into your executable. Instead, the file should probably have just the numbers in it, which you then read in yourself. Can you describe your assignment more? Were you given a sample file full of data to use?
@MiiNiPaa
Alrights , so if i am not supposed to use %f as specifier , then which specifier should i use ?
@booradley60
Uhm okays sorry if it wasn't clear what i meant by a seperate file is that the daily rainfall data will be fed to external sources ( external data files ) as arrays and i am supposed to :
Write a program to show a menu with options that allows the user to display
1. The total rainfall of a selected month
2. The maximum rainfalls of the selected month.
3. The month with the lowest average rainfall and the value of the lowest average rainfall
among all the months. (eg. Among three months that you have chosen).
Set total=0; just before line 38. Otherwise you'll get the right answer the first time you ask for it, but subsequent times will be adding to the previous total.
Swap lines 41 and 42. You want to print the final total, not the total after each day, right?