I'm trying to be able to call the vendingmachine function and have it give me a table of the stuff i got from the file but it gives me crazy numbers like -858993460. I have to be able to change the individual amounts and prices before calling the function so it can give me different numbers.
Cola 0.75 20 Ruby Red Blast 1.00 10 Lemon Fizz 0.75 8 Grape Soda 0.90 5 Citrus Flip 0.85 0 Habanero Surprise 0.80 11 ^^This is the text file im working with
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
struct soda{
string name;
double price;
int amount;
};
void vendingmachine(struct soda[6]);
int main(){
ifstream inFile;
soda soda[6];
inFile.open ("machine.txt");
if ( inFile.fail() )
{
cout << "Error: Data file could not be opened" << endl;
exit (EXIT_FAILURE);
}
for(int i=0; i < 6; i++){
getline(inFile, soda[i].name);
inFile >> soda[i].price;
inFile >> soda[i].amount;
inFile.ignore(100,'\n');
}
cout << "Welcome to the vending machine!" << endl;
cout << endl;
vendingmachine(soda);
return 0;
}
void vendingmachine(struct soda soda[6]){
cout << "***************************************************************" << endl;
cout << " " << "Drink Name" << " " << "Price Per Can" << " " << "Number in Machine" << endl;
for( int i=0; i < 6; i++){
cout << setw(17) << soda[i].name << setw(16) << soda[i].price << setw(20) << soda[i].amount << endl;
}
cout << "***************************************************************" << endl;
}
Thanks everyone, i changed it to how it should be.