@hidden dragon
Screenshots!
Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!
11 messages · Page 1 of 1 (latest)
@hidden dragon
Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<string>
using namespace std;
int main()
{
int age=0;
int totalage=0;
int group1=0, group2=0, group3=0, group4=0, group5=0;
int snacks_group_1=0, snacks_group_2=0, snacks_group_3=0, snacks_group_4=0, snacks_group_5=0, snacks_group_6=0, snacks_group_7=0;
int total=0;
int youngest=500;
int oldest=0;
int snacks;
while(age>=0)
{
cout<<"==========================================="<<endl;
cout<<"Movie theater snacks available for purchase"<<endl;
cout<<"==========================================="<<endl;
cout<<"1-Soft Drink"<<endl;
cout<<"2-Popcorn"<<endl;
cout<<"3-Nachos"<<endl;
cout<<"4-Soft drink and Popcorn"<<endl;
cout<<"5-Soft drink and Nachos"<<endl;
cout<<"6-Organic and Gluten-free snacks"<<endl;
cout<<"7-None"<<endl;
cout<<"==========================================="<<endl;
cout <<("Enter age of attendee(-1 to quit): ");
cin >>age;
totalage=totalage+age;
if(age>0)
{
cout<<"Movie theater snack purchased. (Select items 1 - 7):"<<endl;
cin>>snacks;
if(snacks==1)
{
snacks_group_1++;
}
else if(snacks==2)
{
snacks_group_2++;
}
else if(snacks==3)
{
snacks_group_3++;
}
else if(snacks==4)
{
snacks_group_4++;
}
else if (snacks==5)
{
snacks_group_6++;
}
else
{
snacks_group_7++;
}
}
if(youngest>age && age>0)
{
youngest=age;
}
if(oldest<age && age>=0)
{
oldest=age;
}
if(age>=0 && age<=18)
{
group1++;
age=0;
total++;
}
else if(age>19 && age<=30)
{
group2++;
age=0;
total++;
}
else if(age>30 && age<=40)
{
group3++;
age=0;
total++;
}
else if(age>40 && age<=60)
{
group4++;
age=0;
total++;
}
else if(age>60)
{
group5++;
age=0;
total++;
}
}
if(age == -1)
{
cout<<"=========================================="<<endl;
cout<<"THEATER STATS PROGRAM RESULTS"<<endl;
cout<<"=========================================="<<endl;
cout <<"\nage 0-19: " <<group1 <<"\n";
cout <<"age 19-30: " <<group2 <<"\n";
cout <<"age 31-40: " <<group3 <<"\n";
cout <<"age 41-60: " <<group4 <<"\n";
cout <<"over 60: " <<group5 <<"\n\n";
cout <<"\The average age was: " <<totalage/total <<"\n";
cout <<"The youngest person in attendance was " <<youngest<<".\n";
cout <<"The oldest person in attendance was " <<oldest<<".\n\n";
cout<<"=========================================="<<endl;
cout<<"Theater Concession Stand sales"<<endl;
cout<<"=========================================="<<endl;
cout<<"Soft Drink (such as Coca Cola, ICCEE, Mineral Water etc.):"<<snacks_group_1<<"\n";
cout<<"Popcorn:"<<snacks_group_2<<"\n";
cout<<"Nachos:"<<snacks_group_3<<"\n";
cout<<"Soft drink and Popcorn:"<<snacks_group_4<<"\n";
cout<<"Soft drink and Nachos:"<<snacks_group_5<<"\n";
cout<<"Organic and glutten-free snacks:"<<snacks_group_6<<"\n";
return 0;
}
}
That's the code I've been working on
Which input are you trying to validate? If it's the number for snacks, you already have the basic structure in place, but you treat all numbers higher than 5 as if it's a 7. It looks like a mistake that a value of 5 results in incrementing snacks_group_6. Nothing increments snacks_group_5 and there is no check for a snack value of 6. To properly check for values higher than 7, you should also have a specific check for 6 and 7, and use the else to catch the invalid values.
Thanks for the help, I corrected what you told me and I used a do-while loop which help me figure it out
!solved
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity
@hidden dragon
Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.
@hidden dragon Has your question been resolved? If so, run !solved :)