I'm having problems with this c++ program.
I need to read a file containing years on each line, and determine if the year is a leap year.
The isLeap function looks fine, i'm just having problems actually reading the file and implementing the function.
Can anyone help me out?
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
using namespace std;
char *isLeap(int year) {
char *result = new char[20];
if (year <= 1) {
sprintf(result, "%d error\n", year);
} else {
if (year % 400 == 0) {
sprintf(result, "%d yes\n", year);
} if (year % 100 == 0) {
sprintf(result, "%d no\n", year);
} else if (year % 4 == 0) {
sprintf(result, "%d yes\n", year);
} else {
sprintf(result, "%d no\n", year);
}
}
return result;
}
int main()
{
char filename;
int year;
cout << "Please enter the filename: " << endl;
cin >> filename >> endl;
while (filename != EOF)
{
cout << filename<< endl;
return 1;
}
return 0;
}