i have this table first:
if number of registrants = 1- 3, charge price = 150.
if number of registrants = 4 - 9, charge price = 100
if number of registrants = 10 or more, charge price = 90
this is what it should do but is not working why?
the program should display the total number of people registered, the total charge, and the average charge per registrant. this is my code:
#include %26lt;iostream%26gt;
using std::cout;
using std::cin;
using std::endl;
int main()
{
//declare variables
int registrants = 0;
double fee = 0.0;
int totalPeople = 0;
double totalCharge = 0.0;
double average = 0.0;
//get input from the user
cout %26lt;%26lt; "Enter number of registrants (Enter 0 to stop the program): ";
cin %26gt;%26gt; registrants;
//get the registration information for programming seminars
while (registrants != 0)
{
if (registrants %26gt;= 1 %26amp;%26amp; registrants %26lt;= 3)
fee = 150;
else if (registrants %26gt;= 4 %26amp;%26amp; registrants %26lt;= 9)
fee = 100;
else if (registrants %26gt; 10)
fee = 90;
C++ help please!?
#include %26lt;iostream%26gt;
using namespace std;
int main() {
int people = 1;
int fee = 0;
int totalpeople = 0;
int totalfee = 0;
while(people %26gt; 0) {
cout %26lt;%26lt; "Enter number of registrants for this company (Enter 0 to exit): %26lt;%26lt; endl;
cin %26gt;%26gt; people;
if(people %26gt; 9) {
fee = 90;
}
elseif(people %26gt; 3) {
fee = 100;
}
else {
fee = 150;
}
totalpeople += people;
totalfee += (people * fee);
}
cout %26lt;%26lt; "Total people attending: " %26lt;%26lt; totalpeople %26lt;%26lt; endl;
cout %26lt;%26lt; "Total fees collected: " %26lt;%26lt; totalfees %26lt;%26lt; endl;
cout %26lt;%26lt; "Average fee per person: " %26lt;%26lt; totalfees / totalpeople %26lt;%26lt; endl;
return 0;
}
Reply:this is the version which i think should work..
//get input from the user
cout %26lt;%26lt; "Enter number of registrants (Enter 0 to stop the program): ";
cin %26gt;%26gt; registrants;
//get the registration information for programming seminars
while (registrants != 0)
{
if (registrants %26gt;= 1 %26amp;%26amp; registrants %26lt;= 3)
fee = 150;
else if (registrants %26gt;= 4 %26amp;%26amp; registrants %26lt;= 9)
fee = 100;
else
fee = 90;
//get input from the user
cout %26lt;%26lt; "Enter number of registrants (Enter 0 to stop the program): ";
cin %26gt;%26gt; registrants;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment