mardi 5 octobre 2021

Isn't || mean or? But why am i getting errors for my Leap year code?

Ok, so I been making a leap-year code that is supposed spit out years (1-10000); month (1-12) and (days with leap year). I'm in the month = 2 (February where there is a day of leap from 28-29) depending on the year. I made it to include || as an "OR" but it keeps coming as error, and also tried else but came up same.

#include <stdio.h> int main() {

int year = 2021;
int month = 12;
int day = 32; 

//printf("Enter an integer: ");
//scanf("%d", &year);

// true if number is less than 0
//Year
if (year > 10000 || year < 1) {
    printf("Error: Invalid year\n");
}else{

if(year <= 10000 || year >= 1){
  printf("%d\n", year); 
    
 }
}

//Month
if (month > 12 || month < 1) {
    printf("Error: Invalid month\n");
}else{

if(month <= 12 || month >= 1){
  printf("%d\n", month); 
    
 }
}
//day (January)
if ((month = 1) && (day > 1 || day < 31)) {
   printf("%d\n", day);
    
}else{

if ((month = 1) && (day < 1 || day > 31)) {
  printf("Error: Invalid day\n");
       
    }
}

//Febuary
if ((year%400 == 0) && (month = 2) && (day > 1 || day < 29)) {
printf("%d\n", day); 
||
if ((year%400 == 0) && (month = 2) && (day < 1 || day > 29)) {
printf("Error: Invalid day\n");
    
}else{

if ((month = 2) && (day > 1 || day < 28)) {
printf("%d\n", day);
||
if ((month = 2) && (day < 1 || day > 28)) {
  printf("Error: Invalid day\n");


  }

 }
    return 0;
}

}

}

The specific program i used was JupyterLab, and this was the output:enter image description here

Aucun commentaire:

Enregistrer un commentaire