i'm trying to write a simple program in the console, simple program to store data that is input from the user. simple numbers. the result i'm getting is 0 0 0. i've been trying to prompt the user to input a day, month, and year, save that data to a file using the fstream library, and then read it and print it to the screen, but failed to understand what i'm doing wrong. any help ?
#include "iostream"
#include "string"
#include "fstream"
/* ********************@ Salary Calculator @********************
* Store the date of the day - 01.12.22 example V
* Store Name of the day
* Store Number of hours of day
*
*/
using std::cout; using std::cin; using std::string; using std::endl;
using std::ios; using std::ofstream; using std::fstream;
int getDate(int day, int month, int year, char key)
{
cout << "\nEnter the Day : "; cin >> day;
cout << "\nEnter the Month : "; cin >> month;
cout << "\nEnter the Year : "; cin >> year;
cout << "\nDate Entered : " << day << "." << month << "." << year;
cout << "\nWould You Like To Change The Date ? (Y/N) ";
cin >> key;
if (key == 'y')
{
int main();
}
else if (key == 'n')
{
cout << "\nDate Saved";
}
return day, month, year;
}
void writeToFile(int day, int month, int year)
{
ofstream Data;
Data.open("Data.txt", ios::app);
Data << day << endl;
Data << month << endl;
Data << year << endl;
Data.close();
}
void readFromFile()
{
fstream Data;
Data.open("Data.txt", ios::in);
if (Data.is_open())
{
string line;
// getline() reads a line of text from file object (fstream Data) and stores it in string 'line'
while (getline(Data, line))
{
cout << line << '\n';
}
}
Data.close();
}
int main()
{
char key{};
int day{}, month{}, year{};
getDate(day, month, year, key);
writeToFile(day, month, year);
readFromFile();
return 0; system("pause>0");
}