Question
Make a program that should have Date (Randomize start of the month) Weather Status of those certain Days of the Week: Sunny, Cloudy, or Rainy
Make a program that should have
- Date (Randomize start of the month)
- Weather Status of those certain Days of the Week: Sunny, Cloudy, or Rainy (Randomized)
- Print the Calendar (Month view only)
Expected Output: In each run of the program, there will be a random start of the month and weather status. Example output:
Note: This is a discussion during the topic of our union, structures, and enum, so please include it if possible. Please put the code itself, not the photo. No need for inputs, just initialize everything inside the code and randomize what should be outputted (as indicated in the instructions) Show the side-by-side interpretation of the algorithm to its corresponding code. Use only C programming (NOT C++).
Here is my previous code also, the problem here is I cannot put the weather like in the example output, please just modify this so it will look the same on the example output. Thanks!
#include
//enum defining the week typedef enum { Sun, Mon, Tue, Wed, Thu, Fri, Sat } Week; //enum defining the weather typedef enum { Sunny, Cloudy, Rainy } Weather; //enum defining the month typedef enum { Jan, Feb, Mar, Apr, May, Jun, July, Aug, Sept, Oct, Nov, Dec } Month;
char* getMonth(Month month); int getRandom(int si, int ei); void showCalender( Week start, int len , char* month);
int main() { //seed for generating random time srand(time(0)); // getting random start Week sdate = getRandom(Sun,Sat); // getting random month Month month = getRandom(Jan,Dec); // getting random days of the month int days = getRandom(28,31); //getting the name of the month char* month_ = getMonth(month); //call to print the calender showCalender(sdate,days,month_); system("pause"); return 0; }
//function to get the month name char* getMonth(Month month) { switch (month) { case Jan: return "January"; case Feb: return "February"; case Mar: return "March"; case Apr: return "April"; case May: return "May"; case Jun: return "June"; case July: return "July"; case Aug: return "August"; case Sept: return "September"; case Oct: return "October"; case Nov: return "November"; case Dec: return "December"; } return ""; } //function to get a random value for a given range int getRandom(int si, int ei) { //since , there is no specific thing to get output for range , we can deduce this formula int val = (rand() % (ei - si + 1)) + si; return val; } //function to print the calender void showCalender( Week start, int len , char* month) { //it will be used to calculate the week day Week weekD = start % 7;
int day; printf(" %s ",month); printf(" Sun Mon Tue Wed Thu Fri Sat "); // it will print white spaces before the start of the date for (day=0; day printf("%7d", day); //generating random weather Weather wday = getRandom(Sunny,Rainy); //storing the random weather w.r.t to their weather if(wday == 0) { sunny[s] = day; s++; } else if(wday == 1) { cloudy[c] = day; c++; } else { rainy[r] = day; r++; } //used to print next line if(weekD==0) printf(" "); } printf(" "); //printing rainy days printf(" Rainy at the days of : "); int i; for( i = 0 ; i //printing cloudy days printf(" Cloudy at the days of : "); for( i = 0 ; i //printing sunny days printf(" Sunny at the days of : "); for( i = 0 ; i }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started