#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const string ID = "David Lab 17";
int main()
{
ofstream fout;
string exit;
int year,
possible, // chance is possible
probable = 0, // chance is probable
definite, // chance is definite
invalid,
unequal;
fout.open("David Lab17.out");
cout << "Running Lab 17... " << ID << endl << endl;
cout << "Enter a year: ";
cin >> year;
fout << ID << endl << endl;
// bool
if (year % 4 == 0)
{ possible = true;
}
if (possible % 400 == 0)
{ probable = true;
}
if (probable != 0)
{ definite = true;
fout << year << "is a leap year";
}
if (year < 0)
{ invalid = true;
fout << year << "is not a valid year";
}
if (probable = 0)
{ (unequal = true);
fout << year << "is not a leap year";
}
// exit routine
cout << "Press any character and return to exit";
cin >> exit;
return 0;
}
For some reason, my output only shows my const string, not "(year) is a leap year" or "(year) is not a leap year". Can someone help me out?
(probable = 0)
Did you mean (probable == 0)
?
What is the variable unequal
for? Looks like it never gets used.
Last edited on
OOps, I did mean (probable == 0)...
unequal is for when the year does not equal a leap year
Oh, I see I messed the formula up a little bit
Ok, I changed it to this, but it still won't print anything but the const string ID
if (year % 4 == 0)
{ possible = true;
}
if (possible % 100 != 0)
{ probable = true;
}
if (probable % 400 == 0)
{ definite = true;
fout << year << " is a leap year";
}
if (year < 0)
{ invalid = true;
fout << year << " is not a valid year";
}
if (possible == 0)
{ (unequal = true);
fout << year << " is not a leap year";
}
Ihaven't really looked at your program (please use [ code ] [ /code ] tags), but you could implement a isLeapYear() function in a much cleaner manner:
1 2 3 4
|
bool isLeapYear(int year)
{
return (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0));
}
|
Last edited on
Try changing fout to cout.