Hi I'm having trouble with a programming assignment. I'm still a huge beginner at C++. The assignment is to design a program for a movie rating guide. Each theater patron enters a value from 0 to 4 indicating the number of stars the patron awards to the guide's featured movie of the week. The program is supposed to execute continuously until a negative number is entered to quit. At the end of he program, it should display the average star rating of a movie.
This is what I have so far. I'm having trouble with the while loop part because I think my logic is incorrect somewhere in there. Should I use a different sentinal value?? It lets me enter one value but it doesn't let me continue after that.
// Declare and initialize variables.
double numStars; // star rating.
double averageStars; // average star rating.
double totalStars = 0; // total of star ratings.
int numPatrons = 0; // keep track of number of patrons
// This is the work done in the housekeeping() function
// Get input.
cout << "Enter rating for featured movie: ";
cin >> numStars;
// This is the work done in the detailLoop() function
// Write while loop here
while (numStars >= 0)
totalStars = numStars++;
averageStars = totalStars / numPatrons;
// This is the work done in the endOfJob() function
cout << "Average Star Value: " << averageStars << endl;
cin >> numStars;
} // End of main()
it doesnt let you continue because of your while loop... what you told him is to do this loop while numStars are equal or greater than 0 and numStar will be always greater or equal to 0 because whenever you input that number it is stuck in there.. try to put negative number and see what happens .. it skips the loop.. but it is not what you want. you should try do while loop. include line 17 and 18 inside of loop.
and i give you little hint :line 24 should be like totalStars += numStars;... this way it wil always add to totalStars what is in numStars. numStars++ will add +1 to numStars so if numStars is 5 after numStars++ it will be 6.. let me know if you need any help..