I am new to C++ and I am required to make a vehicle billing system program (command line)
My problem is when I try to add a name with spaces (John Doe) the program goes into a loop crash.
here is a snippet of my code. Can you show me where am I doing wrong?
a little bit about the program I am trying to code. It starts with a login and upon successful login, it takes the user to a menu.
this is the code snippet after you choose menu one. it is supposed to open a text file and register the details that the user have inputted.
#include <iostream>
#include <stdlib.h>
#include<string>
#include<fstream>
using namespace std;
struct car {
//attributes
ofstream writer;
ifstream Reader;
//variables for sample 1 menu
string date;
string vehicleNumber;
string manufacturer;
string manufacturerCountry;
int manufactureYear;
int mileage;
string registeredOwner;
//variables for sample 2 menu
double price [10],qty[10];
double total;
};
//function menu for car details
void carDetails()
{
car details;
//adds the data to the following car data fields
cout <<"Date = "; cin >> details.date;
cout <<"Vehicle Number = "; cin >> details.vehicleNumber;
cout <<"Manufacturer = "; cin >> details.manufacturer;
cout <<"Manufacturer Country = "; cin >> details.manufacturerCountry;
cout <<"Manufacture Year = "; cin >> details.manufactureYear;
cout <<"Mileage in kilometers = "; cin >> details.mileage;
cout <<"Registered Owner = "; cin >> details.registeredOwner;
//opens and write a .txt file for car info
details.writer.open("car details.txt",
std::ios_base::app);
//adds following car info data fields to the txt file
details.writer <<"Date = " <<details.date << endl;
details.writer <<"Vehicle Number = " << details.vehicleNumber << endl;
details.writer <<"Manufacturer = " <<details.manufacturer <<endl;
details.writer <<"Manufacturer Country = " <<details.manufacturerCountry <<endl;
details.writer <<"Manufacture Year = " <<details.manufactureYear <<endl;
details.writer <<"Mileage in kilometers = " <<details.mileage <<endl;
details.writer <<"Registered Owner = " <<details.registeredOwner <<endl;
//dash break
details.writer <<"\n---------------------------------------";
details.writer.close();
cout <<"\n Press any key and press ENTER to return back to Main Menu: ";
cin >> details.date;
//clears console
system("cls");
}