how can i make my program output this

Example Output 1 (not a leap year, input is in bolded italics):
Enter a year: <b>1800</b>
Is the year evenly divisible by 4? Yes.
Is the year evenly divisible by 100? Yes.
Is the year evenly divisible by 400? No.
1800 is not a leap year.


Example Output 2 (is a leap year, input is in bolded italics):
Enter a year: <b>2364</b>
Is the year evenly divisible by 4? Yes.
Is the year evenly divisible by 100? No.
Is the year evenly divisible by 400? No.
2104 is a leap year.


i have to create three Boolean variables for this but i'm confused on how to do so. This is what i have so far but i don't feel like i'm on the right track.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  #include <iostream>
#include <string>
using namespace std;

int main ()
{
    int year;

    cout << "Enter a year: ";
    cin >> year;
    cout << endl;
    
    if (leap_year(year) == true)
    {
        cout << "Is the year evenly divisible by 4? Yes." 
    }
    if (leap_year(year) == false)
    {
        cout << "Is the year evenly"
    }
        

    

return 0;
}
No, you aren't :P. If I understand correctly you need 3 boolean variables, one of which is true when the number is divisible by 4, the other is true when it is divisible by 100 and the last one when the number is divisble by 400. And then, according to each variable, make certain outputs. Also, decide whether it's a leap year or not. I'm not going to give you full code, but some code and you'll have to complete it by yourself.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<iostream>
using namespace std;

int main(){
int year;
cout<<"Enter a year:\n";
cin>>year;
bool div_by_4 = false;
bool div_by_100 = false;
bool div_by_400 = false;

if (//divisible by 4){
// do something with variable div_by_4

}
if (//divisible by 100){
// do something with variable div_by_100
}
if (//divisible by 400){
//do something with variable div_by_400
}
if (//can be divided by 4, div_by_4 ){
//output "is this year evenly divisible by 4? yes.\n"
}
else if(//cannot be divided by 4, div_by_4){
//output "is this year... no\n"
}
if (//can be divided by 100, div_by_100){
//output "is this... yes\n"
}
else if(//cannot be divided by 100, div_by_100){
// output "is this... no\n"
}
if (//can be divided by 400, div_by_400){
//output "is this... yes\n"
}
else if(//cannot be divided by 400, div_by_400){
//output "is this... no\n"
}
if (//is divided by 4 and not by 100){
//output "leap year\n"
}
if (//is divided by 400){
//output "leap year\n"
}
else{
//output "not leap year\n"
}
return 0;
}
Last edited on
Topic archived. No new replies allowed.