Question

This is my program in C. I should be able to print out Monday, Tuesday and...

This is my program in C. I should be able to print out Monday, Tuesday and Wednesday. However, I am not sure what I am doing wrong. Please tell me.

So far I get these errors:

warning: ‘enum day’ declared inside parameter list will not be visible outside of this definition or declaration

const char* DayToString(enum color x)// I guess this is just a warning, nothing wrong

error: parameter 1 (‘x’) has incomplete type

const char* DayToString(enum color x) //I would assume that color is the type

error: expected expression before ‘day’

MyMonday = day(j);

          ^~~~~

typedef enum {Monday, Tuesday, Wednesday, Thursday, Friday} day; //declare an day enum

                                day MyMonday;

                                day MyTuesday;

                                day MyWednesday;

                               

                               

                const char* DayToString(enum day x) //create function DayToString that I can use later to print a day

                                {

                                                switch (x)

                                                {

                                                                case Monday : return " Monday";

                                                                case Tuesday: return " Tuesday ";

                                                                case Wednesday: return " Wednesday ";

                                                                case Thursday: return " Thursday ";

                                                                case Friday: return " Friday ";

                                                }

                                }

void main(){

                int j = 1; //declare int j that I can use to print Monday

                MyMonday = day(j);

                int y = 2;

                MyTuesday = day(y);

                int z = 5;

                MyWednesday = day(z);

               

                                                               

                                printf("\n Color #1: %s", DayToString(MyMonday));// should print Monday

                                printf("\n Color #1: %s", DayToString(MyTuesday));

                                printf("\n Color #1\n: %s", DayToString(MyWednesday));

                }

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include<stdio.h>

typedef enum {Monday, Tuesday, Wednesday, Thursday, Friday} day; //declare an day enum

day MyMonday;
day MyTuesday;
day MyWednesday;

/**
 * Here you used "enum day x" as a parameter but since you have already typedefed enum above as day.
 * That is why wherever you write "day" it means "enum day", therefore, "enum day x" would mean "enum enum day x"
 * and that's invalid!
 */
const char* DayToString(day x) //create function DayToString that I can use later to print a day
{
    switch (x)
    {
        case Monday : return " Monday";
        case Tuesday: return " Tuesday ";
        case Wednesday: return " Wednesday ";
        case Thursday: return " Thursday ";
        case Friday: return " Friday ";
    }
}

int main(){
    int j = 1; //declare int j that I can use to print Monday
    MyMonday = (day)j;
    int y = 2;
    MyTuesday = (day)y;
    int z = 3;
    MyWednesday = (day)z;
    printf("\n Color #1: %s", DayToString(MyMonday));// should print Monday
    printf("\n Color #1: %s", DayToString(MyTuesday));
    printf("\n Color #1: %s", DayToString(MyWednesday));
}

SAMPLE OUTPUT:

FOR ANY HELP JUST DROP A COMMENT

Add a comment
Know the answer?
Add Answer to:
This is my program in C. I should be able to print out Monday, Tuesday and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • week_days<- c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") How do i write a line of code...

    week_days<- c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") How do i write a line of code that will select the days Wednesday, Saturday, and Sunday in Rstudio?

  • Write a C++ Program. You have a following class as a header file (dayType.h) and main()....

    Write a C++ Program. You have a following class as a header file (dayType.h) and main(). #ifndef H_dayType #define H_dayType #include <string> using namespace std; class dayType { public:     static string weekDays[7];     void print() const;     string nextDay() const;     string prevDay() const;     void addDay(int nDays);     void setDay(string d);     string getDay() const;     dayType();     dayType(string d); private:     string weekDay; }; #endif /* // Name: Your Name // ID: Your ID */ #include <iostream>...

  • Why isnt my MyCalender.java working? class MyCalender.java : package calenderapp; import java.util.Scanner; public class MyCalender {...

    Why isnt my MyCalender.java working? class MyCalender.java : package calenderapp; import java.util.Scanner; public class MyCalender { MyDate myDate; Day day; enum Day { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }    public static void main(String[] args) { Scanner sc= new Scanner(System.in); System.out.println("Enter date below :"); System.out.println("Enter day :"); int day = sc.nextInt(); System.out.println("Enter Month :"); int month = sc.nextInt(); System.out.println("Enter year :"); int year = sc.nextInt(); MyDate md = new MyDate(day, month, year); if(!md.isDateValid()){ System.out.println("\n Invalid date . Try...

  • Hello, I have a bug in my code, and when I run it should ask the...

    Hello, I have a bug in my code, and when I run it should ask the user to enter the month and then the year and then print out the calendar for the chosen month and year. My problem with my code is that when I run it and I enter the month, it doesn't ask me for the year and it prints all the years of the month I chose. Please help! Code: #include "calendarType.h" #include <iostream> using namespace...

  • how to check enums in C let us say I have the following enum: enum days{...

    how to check enums in C let us say I have the following enum: enum days{ MONDAY, SUNDAY, THURSDAY } ; I want to check if a struct that contains this enum has a valid value for example typedef struct { int date; enum day name; } complete_date; so now I want to check if a complete_date has a valid enum it can only be valid if it is MONDAY,SUNDAY, OR THURSDAY. i want to assert that becuase if it...

  • i'm trouble getting my program to print this output and repeat until asked to quit the...

    i'm trouble getting my program to print this output and repeat until asked to quit the program Enter a telephone number using letterss (EXIT to quit): GET LOAN The corresponding telephone number is: 438-5626 Here's my code: #include <stdio.h> #include <string.h> char getNumber(char aC) { char c = ' '; switch (aC) { case 'A': case 'B': case 'C': c = '2'; break; case 'D': case 'E': case 'F': c = '3'; break; case 'G': case 'H': case 'I': c...

  • THIS CODE SHOULD BE MODIFIED TO READ SuperMarket.dat instead of Inputting and Outputting. SuperMarket.dat Monday 4...

    THIS CODE SHOULD BE MODIFIED TO READ SuperMarket.dat instead of Inputting and Outputting. SuperMarket.dat Monday 4 Monday 6 Monday 2 Tuesday 3 Tuesday 2 Wednesday 3 Wednesday 5 Wednesday 7 Thursday 5 Friday 4 Friday 3 Friday 4 Saturday 8 Saturday 8 Saturday 8 Sunday 0 QUESTION: Write the control break code, including the code for the dayChange() method, in the main() method. // SuperMarket.java - This program creates a report that lists weekly hours worked // by employees of...

  • Please help modify my C program to be able to answer these questions, it seems the...

    Please help modify my C program to be able to answer these questions, it seems the spacing and some functions arn't working as planeed. Please do NOT copy and paste other work as the answer, I need my source code to be modified. Source code: #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { char title[50]; char col1[50]; char col2[50]; int point[50]; char names[50][50]; printf("Enter a title for the data:\n"); fgets (title, 50, stdin); printf("You entered: %s\n", title);...

  • I need to write a program in java using two array lists. I need to program...

    I need to write a program in java using two array lists. I need to program to prompt the user to enter a day of the week and return an output of a predetermined temperature for the day they selected. I also need the program the output the average of daily temperatures across the week if the user inputs "week". So basically if i set the temperatures to something arbitrary i.e.: Monday = 50 Tuesday = 55 Wednesday = 52...

  • C programming Question1 (a) Write a C program that will print out all command line arguments,...

    C programming Question1 (a) Write a C program that will print out all command line arguments, in reverse order, one per line. Prefix each line with its index. 6 marks] (b) Consider this C code snippet int a- 100 int b- 42; inte p- &a; int q-b; p qi printf ("%d %d\n" ,a,*p); When this code is executed, what numbers will it print? [2 marks] (c) Consider this C program int main(int argc,char argv) char* target- "Apple" char vord[100] printf...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT