I am trying to take input from a file and and insert them into an Array of class objects. I am having some trouble understanding this can anyone help.
The text file contains a name, price, and quantity.
Pleaes ignore the comments Ithose were just things I was playing around with.
Essentially I am trying to modify my program so that the machine doesn't have built in data; it in fact will now have data programed into it via a file...
Code:
#include <iostream>
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include "CashRegister.h"
#include "dispenserType.h"
using namespace std;
//void showSelection(string, int);
void showSelection();
void sellProduct(dispenserType& product, cashRegister& pCounter);
//dispenserType productlist[8];
//struct productsinfo
//{
// string name;
// int noi;
// int cost;
//}
int main()
{
ifstream inStud;
inStud.open("items.txt");
if (!inStud)
{
cout <<"** Can't open input file Stud**"<< endl;
return 1;
}
Get_Inf(inStud, StudDB[])
//dispenserType obj[8];
//ifstream inF1;
//int i = 0;
//while(!inF1.eof())
//{
// inF1 >> obj[i].name;
// intf1 >> obj[i].numberOfItems;
// inf1 >> obj[i].cost;
// i++;
//}
cashRegister counter;
dispenserType candy (100, 50);
dispenserType chips (100, 65);
dispenserType gum (75, 45);
dispenserType cookies (100, 85);
int choice;
//cout << "*** Welcome to Shelly's Candy Shop ***" << endl;
//for (int a = 0; a < 8; a ++)
//{
//showSelection(obj[a].name, a);
//}
//cout << "Press 99 to exit" << endl;
//cin >> choice;
showSelection();
cin >> choice;
while (choice !=9)
{
switch (choice)
{
case 1:
sellProduct (candy, counter);
break;
case 2:
sellProduct (chips, counter);
break;
case 3:
sellProduct (gum, counter);
break;
case 4:
sellProduct (cookies, counter);
break;
default:
cout << "Invalid selection." << endl;
}
//cout << "*** Welcome to Shelly's Candy Shop ***" << endl;
//for (int a = 0; a < 8; a ++)
//{
// showSelection(obj[a].name, a);
//}
//cout << "Press 99 to exit" << endl;
//cin >> choice;
showSelection();
cin >> choice;
}
return 0;
}
//void showSelection(string whatever, int a)
//{
// cout << "Press", a+1, "for", whatever << endl;
//}
void showSelection()
{
cout <<"*** Welcome to Shelly's candy Shop ***" << endl;
cout <<"To select an item, enter " << endl;
cout <<"1 for Candy" << endl;
cout <<"2 for Chips" << endl;
cout <<"3 for Gum" << endl;
cout <<"4 for Cookies" << endl;
cout <<"9 to exit" << endl;
}
void sellProduct(dispenserType& product, cashRegister& pCounter)
{
int amount;
int amount2;
if (product.getNoOfItems() > 0)
{
cout << "Please deposit " << product.getCost()
<< " cents" << endl;
cin >> amount;
while (amount < product.getCost())
{
cout << "Please deposit another "
<< product.getCost() - amount
<< " cents" << endl;
cin >> amount2;
amount = amount + amount2;
}
if (amount >= product.getCost())
{
pCounter.acceptAmount(amount);
product.makeSale();
cout << "Collect your item at the bootom and "
<< "enjoy." << endl;
}
else
cout << "the amount is not enough. "
<< "enjoy." << endl;
cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"
<< endl << endl;
}
}