1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include <iostream>
using namespace std;
struct result
{
int temp;
int wind;
time_t time;
};
FILE *awind;
int main()
{
int option; // user's entered option will be saved in this variable
char ch;
result *readings;
do //do-while loop starts here.that display menu again and again until user select to exit program
{
//Displaying Options for the menu
printf("1) Load a file ");
printf("2) Get weather by date ");
printf("3) View monthly average");
printf("4) Export to excel");
printf("5) Exit Program ");
//Prompting user to enter an option according to menu
printf("Please select an option : ");
scanf_s("%i", &option); // taking option value as input and saving in variable "option"
if (option == 1) // Checking if user selected option 1
{
fopen_s(&awind, "readings.bin", "rb");
if (awind == NULL)
{
perror("Error while opening the file.\n");
exit(EXIT_FAILURE);
}
fseek(awind, 0L, SEEK_END);
int sz = ftell(awind) / sizeof(result);
fseek(awind, 0L, SEEK_SET);
readings = (result*)malloc(sz * sizeof(result));
fread(readings, sizeof(result), sz, awind);
}
else if (option == 2) // Checking if user selected option 2
{
int day, month, year;
printf("Please enter the day (dd): ");
scanf_s("%d", &day);
printf("Please enter the month (mm): ");
scanf_s("%d", &month);
printf("Please enter the year (yyyy): ");
scanf_s("%d", &year);
time_t theTime;
tm *newTime;
theTime = time(NULL);
printf("the time is:%d \n", theTime);
newTime = localtime(&theTime);
printf("the date is:%i%i%i" newTime->tm_mday->, newTime->tm_mon + 1, 1900 + newTime->tm_year);
}
else if (option == 3) // Checking if user selected option 3
{
printf("retrieveing averages:");
}
else if (option == 4) // Checking if user selected option 4
{
printf("exporting file to excel");
}
else //if user has entered invalid choice (other than 1,2,3 or 4)
{
//Displaying error message
cout << "Invalid Option entered" << endl;
}
} while (option != 4); //condition of do-while loop
return 0;
}
|