I'm stuck with accumulators!

Hi, this is my first language and I am taking a class in C++. I know I'm stuck in something simple, but I need help. I can't figure out. My code is not finish yet, but I'm working on it.

Problem: If a ticket cost less than $5 go to movies, otherwise stay home and study. You need to use 10x loop and add 3 accumulators: a)how many went to movies? b) how many stay at home & study? c) total cost of movie tickets?

I'm trying to do a) and b) so far but an error show up when I try to compile. Can you please help me?

#include <iostream>

int main()
{
int ticket,movie_count,home_count;
movie_count = home_count = 0;

for (int i=0; i<10; i++)
{
cout<<"Enter the ticket value: ";
cin>>ticket;

if (ticket < 5)
cout<<"Go to the movies";
movie_count++;
else
cout<<"Stay home and study";
home_count++;
}
cout<<"\n Go to the movies count is " << movie_count<< "\n";
cout<<"\n Stay home count is " << home_count<< "\n";
return 0;
}
Well right off the bat I see that you aren't using { } in association with your if...else statement. You use them fine in your for loop but leave them out here.

Your code should be:
1
2
3
4
5
6
7
8
9
10
if (ticket < 5)
{
cout<<"Go to the movies";
movie_count++;
}
else 
{
cout<<"Stay home and study";
home_count++;
}


Edit: Also, use code blocks when posting your code. Put ["code"] before your code and ["/code"] at the end (without the quotation marks).
Last edited on
Thanks so much!!!!!!
Topic archived. No new replies allowed.