HI all
I am trying to make a small database to help me improve my skill but i am totally stuck so can someone please help me. I want it so if the person enters n it goes to the start of the program and if the user enters y it carries on and saves the file, but I dont know how to evaluate user input.
Can someone please show me what to do lolCode:#include<fstream>// headerfile for output/input #include<iostream> #include<string> using namespace std; int main() { string personname; string activity; string arriving; string answer; ofstream djout; // declare our djoutput djout.open("C:\\TEST.txt"); // opens/creates and edits "TEST.txt" cout << "Please enter the persons name: "; getline (cin, personname); cout << "Please enter the activity: "; getline (cin, activity); cout << "How are they arriving: "; getline (cin, arriving); cout << "Please confirm the details: "; cout << "Name: " << personname << endl; cout << "Activity: " << activity << endl; cout << "Arriving by: " << arriving << endl; cout << "Are the details correct? Y/N" << endl; getline (cin, answer); if (answer == 'y') { djout << personname << endl; djout << activity << endl; djout << arriving << endl; djout.flush(); // to save the file, you must close the file, or flush djout.close(); // the buffer to the file Closing the file will not let // you access it anymore, so only call it when you are // done using the file and it will automatically save // the file for you. Flushing the buffer will write the // buffer to the file and still keep the file open, so // use this function when necessary. } if (answer == 'n') { //I want it to go back to the beginning of the program } else { cout << "System error sorry guys im not always right :)" << endl; } system("pause"); return 0; }
Many thanks
HLA91![]()



LinkBack URL
About LinkBacks




I used to be an adventurer like you... then I took an arrow to the knee.