Help with prime read algorithm while statement

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <string>
#include<iostream>
#include<iomanip>
#include<fstream>
#include <cstdlib>
 

int main()
{
	//housekeeping
	string customerName;
	char typeOfGas;
	double numLitres, salesAmt, gasPrice;

	ofstream  fout("gas.rpt");
	if (!fout.is_open())
	{
		cout << "file not opened";
		system("pause");
		exit(666);
	}

		cout << "Enter Name ";
		getline(cin, customerName);
{
		cout << " How many Litres?";
		cin >> numLitres;

		cout << " What type of gas?";
		cin >> typeOfGas;
	
		cout << "Enter Name on or";
	
			
			if (typeOfGas == 'r' || typeOfGas == 'R')
				gasPrice = 1.28;
			else if (typeOfGas == 'd' || typeOfGas == 'D')
				gasPrice = 1.08;
			else if (typeOfGas == 'p' || typeOfGas == 'P')
				gasPrice = 2.50;

			salesAmt = numLitres * gasPrice;


		fout << fixed << left << setw(20) << "customerName" << right << setw(20) << "typeOfGas" << right << setw(20) << "numLitres" << right << setw(20) << "salesAmt" << endl;

		fout << left <<setw(20) << customerName << right <<setw(20) << typeOfGas << right << setw(20) << numLitres << right << setw(20) << salesAmt << endl;
		

		





		cout << "Program ended successfully" << endl;
		//Print data file
		system("type gas.rpt");
		system("pause");
}
It's not horrible, but it doesn't compile.

Hints:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// 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; }       //
    else if (typeOfGas == 'd' || typeOfGas == 'D') { gasPrice = 1.08; }       //
    else if (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");
}

Topic archived. No new replies allowed.