I'm looking for some help on how to add a prime read algorithm while statement to my code to allow many customers to be able to put their names in to calculate gas prices. I can't seem to figure it out at all. This is my first bit of coding so it's probably going to look horrible to some. Thanks for any help guys this is really bugging me.
// I'm looking for some help on how to add a prime read algorithm while
// statement to my code to allow many customers to be able to put their names
// in to calculate gas prices. I can't seem to figure it out at all.
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
int main()
{
std::ofstream fout("gas.rpt");
if (!fout.is_open())
{
std::cout << "file not opened.\n";
// The usage of system() to perform trivial tasks is nor encouraged
// http://www.cplusplus.com/forum/beginner/1988/
std::system("pause");
exit(666);
}
std::string customerName;
// loop until custormerName is equal to 'exit' <-- from here -------------//
std::cout << "Enter Name "; //
std::getline(std::cin, customerName); //
//
std::cout << "How many Litres?"; //
double numLitres = 0.0; //
std::cin >> numLitres; //
// If you want to use both std::getline and std::cin in your program, //
// you'd better take care of get rid of trailing '\n' in input buffer: //
// http://www.cplusplus.com/forum/general/113238/#msg618762 //
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); //
//
std::cout << "What type of gas (R, D or P)?"; //
char typeOfGas; //
std::cin >> typeOfGas; //
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); //
//
double gasPrice = 0.0; //
if (typeOfGas == 'r' || typeOfGas == 'R') { gasPrice = 1.28; } //
elseif (typeOfGas == 'd' || typeOfGas == 'D') { gasPrice = 1.08; } //
elseif (typeOfGas == 'p' || typeOfGas == 'P') { gasPrice = 2.50; } //
//
double salesAmt = numLitres * gasPrice; //
//
fout << std::fixed //
<< std::left << std::setw(20) << "customerName" //
<< std::right << std::setw(20) << "typeOfGas" //
<< std::right << std::setw(20) << "numLitres" //
<< std::right << std::setw(20) << "salesAmt\n" //
<< std::left << std::setw(20) << customerName //
<< std::right << std::setw(20) << typeOfGas //
<< std::right << std::setw(20) << numLitres //
<< std::right << std::setw(20) << salesAmt << '\n'; //
// <-- to here -------------//
std::cout << "Program ended successfully\n";
std::system("type gas.rpt");
std::system("pause");
}