I want to create a program that asks the user to input values.
The program will ask the user if they want to add more information but when the user wants to add another piece of information the output displays:
First-Question: Answer
Question: Answer
Second-Question:
Question: Answer
This is my code
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<vector>
using namespace std;
void IssueBooks() {
vector<string> bookID;
vector<string> bookTitle;
vector<string> bookAuthor;
vector<string> bookIssuer;
string ID;
string Title, Author, Issuer;
char question;
//get bookID
cout << "Enter book ID: "<<endl;
getline(cin, ID);
bookID.push_back(ID);
//get bookTitle
cout << "Enter book title: "<<endl;
getline(cin, Title);
bookTitle.push_back(Title);
//get bookAuthor
cout << "Enter book author: "<<endl;
getline(cin, Author);
bookAuthor.push_back(Author);
//get bookIssuer
cout << "Enter Issuer Name: "<<endl;
getline(cin, Issuer);
bookIssuer.push_back(Issuer);
ofstream out("IssueRecord.txt");
for (int j = bookID.size() - 1 ; j >= 0 ; j--) {
out << bookID[j] << " " << bookTitle[j] << " " << bookAuthor[j]
<< " " << bookIssuer[j]<<endl;
}
cout << "Do you want to add more books? <Y/N>" << endl;
cin >> question;
switch(question) {
case 'Y' :
IssueBooks();
break;
case 'y' :
IssueBooks();
break;
case 'N' :
break;
case 'n' :
break;
default :
cout << "Invalid input, try again !" << endl;
}
}
int main() {
IssueBooks();
return 0;
}
Thank you