Need help else, else if statments switch case

  • Thread starter Thread starter jekkler
  • Start date Start date
  • Tags Tags
    Switch
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 2K views
jekkler
Messages
1
Reaction score
0
need help else, else if statements... switch case..

need help on the bottom where tryin to define bonusContribution

Code:
// Marcus Molineaux csit 802 assignment 3 t th 645


#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
	int tiksold;
	double newadmpt, mondist, revgen,amnovrhd,monraised,admpct;
	double bonusContribution;
	string charname;
	const double tikprice=5.00;
	cout<<"How many tickets were sold? "<<endl;
	cin>>tiksold;
	cout<<"What percent goes to administrative costs (type in whole number)? "<<endl;
	cin>>admpct;
	newadmpt=admpct/100;
		cout<<"How much prize money was distributed? "<<endl;
	cin>>mondist;
	cout<<"What is the name of the charity? "<<endl;
	cin.ignore();
		getline (cin,charname);
revgen=tiksold*tikprice;
amnovrhd=newadmpt*revgen;
		
monraised=(revgen-amnovrhd)-mondist;
		cout << fixed << showpoint << setprecision(2);
        cout<<"Charity:                               "<<setw(12)<<charname<<endl;
		cout<<"Revenue generated:                    $"<<setw(12)<<revgen<<endl;
		cout<<"Administrative overhead:              $"<<setw(12)<<amnovrhd<<endl;
		cout<<"Deducted prize money:                 $"<<setw(12)<<mondist<<endl;
		cout<<"Money raise for charitable fund:      $"<<setw(12)<<monraised<<endl;
		
		
	if (tiksold>10000) bonusContribution=0;
	
	else if ((tiksold<10000) && (tiksold<25000))bonusContribution=3000;
	
	else if (tiksold<24999 && tiksold>50000)bonusContribution=8000;
	
	else if (tiksold<49999 && tiksold>100000)bonusContribution=15000;
	
    else if (tiksold<99999)bonusContribution=25000;
	
	
		cout<<"Bonus Contribution                    $"<<setw(12)<<bonusContribution;
	
	
	
	return 0;
}
 
Physics news on Phys.org


Your inequalities are going every which way and don't make sense.

Code:
if (tiksold>10000) bonusContribution=0;   // 1
else if ((tiksold<10000) && (tiksold<25000))bonusContribution=3000;  // 2
else if (tiksold<24999 && tiksold>50000)bonusContribution=8000;  //3
else if (tiksold<49999 && tiksold>100000)bonusContribution=15000;  //4
else if (tiksold<99999)bonusContribution=25000; // 5
cout<<"Bonus Contribution                    $"<<setw(12)<<bonusContribution;
Statement 1 says that if there are more than 10,000 tickets sold, there is no bonus.
Statement 2 says that if there are less than 10,000 tickets sold AND less than 25,000 tickets sold, the bonus is 3000. This is equivalent to saying that if fewer than 10,000 tickets are sold, the bonus is 3000.

From these two statements, if there are no tickets sold, the bonus is 3000. If there are 5000 tickets sold, the bonus is 3000. If there are 9999 tickets sold, the bonus is 3000, but if one more ticket is sold, there's no bonus. I'm almost certain that this logic is faulty.

Statement 3 says that if the number of tickets sold is less than 24,999 AND larger than 50,000, the bonus is 8000. There are no numbers that are simultaneously less than 24,999 and larger than 50,000, so there will never be a bonus of 8000 paid.

Statement 4 has a similar problem.

Statement 5 says that if there are less than 99,999 tickets sold, the bonus is 25000.