Here is my source code: (I assure you this is not homework, I am teaching myself programming, and thought I should write a helpful program to learn from.)
Code:
#include <iostream>
#include <string>
#include <fstream>
#include <conio.h>
#include <sstream>
using namespace std;
void WelcomeScreen();
void AddItems();
char nameOfClass[25];
char descriptionOfAssignment[250];
char dueDate[20];
int numAssn; //number of assignments
//int x = 0;
int main()
{
WelcomeScreen();
AddItems();
cout << "\t\t\tHOMEWORK ASSIGNMENT PLANNER" << endl;
cout << "\t\t\tPROGRAMMED BY DAMON VESSEY" << endl;
cout << "##########################################################################" << endl;
cout << endl << endl << endl;
cout << "This program has been successfully terminated." << endl;
getch();
return 0;
}
void WelcomeScreen()
{
system("cls");
cout << "\t\t\tHomework Assignment and Test Planner" << endl;
getch();
return;
}
void AddItems()
{
int x = 0;
ofstream myfileout;
myfileout.open( "HwAssignment.txt", ios::out );
cout << "How many homework assignments do you have?" << endl;
cin >> numAssn;
do {
x++;
cout << "What is the name of the class for which this homework assignment is for?" << endl;
cin.getline( nameOfClass, 25);
myfileout << "[" << nameOfClass << "]";
cout << "Write a description of what your assignment or test covers." << endl;
cin.getline( descriptionOfAssignment, 250);
myfileout << " - " << descriptionOfAssignment;
cout << "What is the date of which your assignment is due or the day you take your test?" << endl;
cin.getline( dueDate, 20);
myfileout << " - (Due: " << dueDate << ")";
myfileout << endl;
} while (x < numAssn);
myfileout.close();
return;
}
I can't figure out why when the program asks "how many homework assignments does it have?", that after the user answers, it skips the question "What is the name of the class for which this homework assignment is for?", and does not even allow the user to input anything, and goes straight to the question "Write a description of what your assignment or test covers." Does anyone know why this happens? I have had this happen to me on several of my other programs, but accidently fixed them somehow, but I want to understand why this happens. Thank you.