I'm a student enrolled in a University beginners programming course.
The problem is:
Write a program capable of using month and day of a given date to calculate the number of days from january 1 that it represents. Make the program capable of computing values for as many as 20 dates.
Data should be input from a data file called DAYS.DAT. The data file should have the following format:
line 1 n (number of dates to be computed)
line 2 month day
line 3 month day
line n+1 month day (all data are integers)
an example data file is :
5
12 7
8 5
1 27
4 18
7 22
print your results to file DAYS.OUT in the following format
Table of dates and days from January 1
Date Days from Jan. 1
December 7 ...
August 5 ...
January 27 ...
etc...
not that you must display thee month in words not numbers
This is what I have so far.. I haven't gotten to putting in the math of the january dates I just want it to output that each of the days is December 7 August 5 and so on... but my output is currently nothing.. it doesn't repeat like i thought it would.. i'm really confused.. only outputs December 7
I know the answer is either do..while, while, or for loops because that is what our chapter is on.. can you guys please give me some hints?
#include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
int x, month, day;
ofstream outfile ("C:\\DAYS.OUT");
outfile<<"Table of dates and days from January 1"<<endl;
outfile<<setiosflags(ios::left)<<setw(20)<<"Date";
outfile<<setiosflags(ios::left)<<"Days from Jan. 1"<<endl;
outfile.close();
ifstream infile ("C:\\DAYS.DAT");
infile>>x;
for (x; x<=20&&x>0; x--)
{
infile>>month>>day;
infile.close();
ofstream outfile ("C:\\DAYS.OUT");
if (month==12,)
{
outfile<<"December "<<day;
outfile.close();
}
else if (month==11)
{
outfile<<"November "<<day;
outfile.close();
}
else if (month==10)
{
outfile<<"October "<<day;
outfile.close();
}
else if (month==9)
{
outfile<<"September "<<day;
outfile.close();
}
else if (month==8)
{
outfile<<"August "<<day;
outfile.close();
}
else if (month==7)
{
outfile<<"July "<<day;
outfile.close();
}
else if (month==6)
{
outfile<<"June "<<day;
outfile.close();
}
else if (month==5)
{
outfile<<"May "<<day;
outfile.close();
}
else if (month==4)
{
outfile<<"April "<<day;
outfile.close();
}
else if (month==3)
{
outfile<<"March "<<day;
outfile.close();
}
else if (month==2)
{
outfile<<"February "<<day;
outfile.close();
}
else if (month==1)
{
outfile<<"January "<<day;
outfile.close();
}
}
}