struct machine {
string name;
double cost;
int num;
};
int main() {
double userMoney;
int i; //count
int leftover;
double change;
const int size = 5;
ifstream file;
file.open("sodas.txt");
machine vending[size] = {};
file >> vending[size].name >> vending[size].cost >> vending[size].num;
//AM I DOING THIS PART RIGHT? IM READING THE FILE INTO THE ARRAY OF STRUCTURES....I THINK
// TEST IF MY FILE WAS READ INTO ARRAY
cout << vending[size].name << " " << vending[size].cost << " " << vending[size].num << endl;
//TEST IF MY FILE WAS READ INTO THE ARRAY
You declared an array vending[] with dimension size. This means that the elements of this array are
vending[0], vending[1], ... vending[size-1].
Thus, when you refer to vending[size] throughout your program you are going beyond the end of the array. You are probably intending to loop through the elements of the array.
I think that you need to read up on arrays (and loops) first.
Please put your code within code tags. It is impossible to see its structure without.