I'm trying to use a for loop to get the users input of numbers and add them together to get a total, however I'm having some trouble. No matter what i've tried, the program always returns the result of "-Nan".
#include <iostream>
usingnamespace std;
int main()
{
int counter;
float price, sub;
cout<<"Enter the number of books in the sale: ";
cin>>counter;
for(int i=1; i <=counter; i++)
{
cout<<"Enter price: ";
cin>>price;
sub = sub + price;
}
cout<<"Subtotal: $"<<sub<<endl;
return 0;
}