Help to complete the code
Apr 19, 2013 at 3:27am UTC
The assignment: To write a program that accepts the user's order and print the total cost of the order including tax or a message that says "Sorry, we do not have that product". Use dimensional variables to save the products and cost.
I wrote a code that input the products and price into ta file, then it gives me the list, but I have no idea what is a dimensional variable and how does the user selects only few products, total the purchase, plus add tax for a grand total.
Here is what I have so far
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char c;
do
{
int menu;
cout << "\t\tEl Carrito Come y Vete" << endl;
cout << "\n\t1. Add product" << endl;
cout << "\t2. Show list of products" << endl;
cout << "\t3. Quit" << endl;
cout << "\nEnter selection: " ;
cin >> menu;
system("cls" );
if (menu==1)
{
ofstream write_products ("products.txt" , ios::app);
if (!write_products)
{
cerr << "File could not be opened" <<endl;
exit (1);
} //final del if
cout << "\t\tEl Carrito Come y Vete" ;
string product;
double cost;
cout << "\n\nEnter product: " ;
cin >> product;
cout << "Enter cost: " ;
cin >> cost;
write_products << product << " " << price <<endl;
}
if (menu==2)
{
ifstream read_products ("products.txt" , ios::in);
if (!read_collection)
{
cerr << "File could not be opened" ;
exit(1);
}
string product;
double cost;
cout << "Product" << " " << "Cost\n" << endl;
while (read_products >> product >> cost)
cout << product << " " << cost << endl;
}
if (menu==3)
{
exit(1);
}
cout << "\nContinue?(y/n): " ;
cin >> c;
system("cls" );
}
while (c != 'n' );
}
Last edited on Apr 19, 2013 at 3:28am UTC
Apr 19, 2013 at 12:36pm UTC
the nomad wrote:I have no idea what is a dimensional variable
dimensional variable is an array ie one dimensional array two dimensional array ect ect ...
Apr 19, 2013 at 6:30pm UTC
Thanks, let me try this then with arrays and see what I can come up with. will post as soon as I find a solution or get stuck again.
Topic archived. No new replies allowed.