fork download
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3.  
  4. struct date
  5. {
  6. int month;
  7. int day;
  8. int year;
  9. };
  10.  
  11.  
  12. struct date *dateUpdate (struct date *today);
  13. int numberOfDays (struct date *d); /*int is returned as its size <= to that of a pointer*/
  14. bool isLeapYear(struct date *d); /*bool is practically always smaller than a pointer*/
  15.  
  16. int main (void)
  17. {
  18. \\some code here doesn't make sense, uninitialized?
  19. struct date thisDay, nextDay;
  20. printf("Enter today's date (mm dd yyyy) : ");
  21. scanf("%i%i%i", thisDay.month, thisDay.day, thisDay.year) /* '&' shouldn't be here*/
  22.  
  23. nextDay = dateUpdate(&thisDay);
  24.  
  25. printf("Tomorrow's date is %i/%i/%.2i.\n", nextDay.month, nextDay.day, nextDay.year % 100);
  26.  
  27. return 0;
  28. }
  29.  
  30.  
  31. struct date *dateUpdate (struct date *today)
  32. {
  33. struct date tomorrow;
  34. int numberOfDays (struct date d);
  35.  
  36. if(today.day != numberOfDays (today))
  37. {
  38. tomorrow = (struct date) {today.month, today.day + 1, today.year};
  39. }
  40. else if(today.month == 12)
  41. {
  42. tomorrow = (struct date) {1, 1, today.year + 1};
  43. }
  44. else
  45. {
  46. tomorrow = (struct date) {today.month + 1, 1, today.year};
  47. }
  48.  
  49. return tomorrow;
  50. }
  51.  
  52. int numberOfDays (struct date *d)
  53. {
  54. int days;
  55. bool isLeapYear (d);
  56. const int daysPerMonth[12] =
  57. {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  58.  
  59. if(isLeapYear (d) && d->month == 2)
  60. {
  61. days = 29;
  62. }
  63. else
  64. {
  65. days = daysPerMonth[d->month - 1];
  66. }
  67.  
  68. return days;
  69. }
  70.  
  71. bool isLeapYear(struct date *d)
  72. {
  73. bool leapYearFlag;
  74.  
  75. if ( (d->year % 4 == 0 && d->year % d->year % 100 != 0) || d->year % 400 == 0)
  76. {
  77. leapYearFlag = true;
  78. }
  79. else
  80. {
  81. leapYearFlag = false;
  82. }
  83.  
  84. return leapYearFlag;
  85. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:18:1: error: expected expression
\\some code here doesn't make sense, uninitialized?
^
prog.cpp:18:23: warning: missing terminating ' character [-Winvalid-pp-token]
\\some code here doesn't make sense, uninitialized?
                      ^
prog.cpp:21:62: error: expected ';' after expression
    scanf("%i%i%i", thisDay.month, thisDay.day, thisDay.year) /* '&' shouldn't be here*/
                                                             ^
                                                             ;
prog.cpp:21:21: error: use of undeclared identifier 'thisDay'
    scanf("%i%i%i", thisDay.month, thisDay.day, thisDay.year) /* '&' shouldn't be here*/
                    ^
prog.cpp:21:36: error: use of undeclared identifier 'thisDay'
    scanf("%i%i%i", thisDay.month, thisDay.day, thisDay.year) /* '&' shouldn't be here*/
                                   ^
prog.cpp:21:49: error: use of undeclared identifier 'thisDay'
    scanf("%i%i%i", thisDay.month, thisDay.day, thisDay.year) /* '&' shouldn't be here*/
                                                ^
prog.cpp:23:5: error: use of undeclared identifier 'nextDay'
    nextDay = dateUpdate(&thisDay);
    ^
prog.cpp:23:27: error: use of undeclared identifier 'thisDay'
    nextDay = dateUpdate(&thisDay);
                          ^
prog.cpp:25:48: error: use of undeclared identifier 'nextDay'
    printf("Tomorrow's date is %i/%i/%.2i.\n", nextDay.month, nextDay.day, nextDay.year % 100);
                                               ^
prog.cpp:25:63: error: use of undeclared identifier 'nextDay'
    printf("Tomorrow's date is %i/%i/%.2i.\n", nextDay.month, nextDay.day, nextDay.year % 100);
                                                              ^
prog.cpp:25:76: error: use of undeclared identifier 'nextDay'
    printf("Tomorrow's date is %i/%i/%.2i.\n", nextDay.month, nextDay.day, nextDay.year % 100);
                                                                           ^
prog.cpp:36:13: error: member reference type 'struct date *' is a pointer; did you mean to use '->'?
    if(today.day != numberOfDays (today))
       ~~~~~^
            ->
prog.cpp:36:35: error: no viable conversion from 'struct date *' to 'struct date'
    if(today.day != numberOfDays (today))
                                  ^~~~~
prog.cpp:4:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'struct date *' to 'const date &' for 1st argument; dereference the argument with *
struct date
       ^
prog.cpp:34:35: note: passing argument to parameter 'd' here
    int numberOfDays (struct date d);
                                  ^
prog.cpp:38:40: error: member reference type 'struct date *' is a pointer; did you mean to use '->'?
        tomorrow = (struct date) {today.month, today.day + 1, today.year};
                                  ~~~~~^
                                       ->
prog.cpp:38:53: error: member reference type 'struct date *' is a pointer; did you mean to use '->'?
        tomorrow = (struct date) {today.month, today.day + 1, today.year};
                                               ~~~~~^
                                                    ->
prog.cpp:38:68: error: member reference type 'struct date *' is a pointer; did you mean to use '->'?
        tomorrow = (struct date) {today.month, today.day + 1, today.year};
                                                              ~~~~~^
                                                                   ->
prog.cpp:40:18: error: member reference type 'struct date *' is a pointer; did you mean to use '->'?
    else if(today.month == 12)
            ~~~~~^
                 ->
prog.cpp:42:46: error: member reference type 'struct date *' is a pointer; did you mean to use '->'?
        tomorrow = (struct date) {1, 1, today.year + 1};
                                        ~~~~~^
                                             ->
prog.cpp:46:40: error: member reference type 'struct date *' is a pointer; did you mean to use '->'?
        tomorrow = (struct date) {today.month + 1, 1, today.year};
                                  ~~~~~^
                                       ->
prog.cpp:46:60: error: member reference type 'struct date *' is a pointer; did you mean to use '->'?
        tomorrow = (struct date) {today.month + 1, 1, today.year};
                                                      ~~~~~^
                                                           ->
fatal error: too many errors emitted, stopping now [-ferror-limit=]
1 warning and 20 errors generated.
stdout
Standard output is empty