-4

I want to make programs that request integer input from the user. if the user enters 0, it will display "Sunday", if the user enters 1, the program will display "Monday" and so on until "Saturday". If the user enters a value outside the range 0 to 6, the program writes "Invalid Days". but when I input a integer the array of days didnt show up. What should I do ?

This is "code.cpp"

main(){
    char days[7] = {"Sunday","Monday","Tuesdat","Wednesday","Thursday","Friday","Saturday"};
    
    int i;
    
    printf("Input Integer:");
    scanf("%d",&i);
    
    if(i < 0 || i >= 7) {
      printf("invalid days\n");
      return;
    }    

    for (i ; i < 7;i++)
    {
        printf("Days: %d\n", days[i]);
    }
}

When i run it at dev C++ it show error,

4 91 F:\IPB\PENUGASAN\MATKUL\MATERI - Copy\APLIKOM\C++\UAS\UAS 2.cpp [Error] too many initializers for 'char [7]'

13 7 F:\IPB\PENUGASAN\MATKUL\MATERI - Copy\APLIKOM\C++\UAS\UAS 2.cpp [Error] return-statement with no value, in function returning 'int' [-fpermissive]

cigien
  • 57,834
  • 11
  • 73
  • 112

1 Answers1

-5
    #include <stdio.h>

main(){
    char* days[7] = {"Sunday","Monday","Tuesdat","Wednesday","Thursday","Friday","Saturday"};
    
    int i;
    
    printf("Input Integer:");
    scanf("%d",&i);
    
    if(i < 0 || i >= 7) {
      printf("invalid days\n");
      return 0;
    }    

    for (i ; i < 7;i++)
    {
        printf("Days: %s\n", days[i]);
    }
}
SSpoke
  • 5,656
  • 10
  • 72
  • 124