Need help else, else if statments switch case

  • Thread starter Thread starter jekkler
  • Start date Start date
  • Tags Tags
    Switch
AI Thread Summary
The discussion focuses on issues with the logic of the bonus contribution calculations in a C++ program. The inequalities used in the if-else statements are flawed, leading to contradictory conditions that could result in incorrect bonus amounts. Specifically, the conditions for bonus contributions are not mutually exclusive or logically sound, causing confusion about the outcomes based on ticket sales. The participants highlight that certain statements, such as those for 8000 and 15000 bonuses, are impossible due to conflicting criteria. Overall, the code requires significant revisions to ensure accurate bonus calculations based on ticket sales.
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


Uh... what, specifically, is your problem?
 


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.
 

Similar threads

Replies
6
Views
3K
Replies
17
Views
3K
Replies
14
Views
5K
Replies
75
Views
6K
Replies
1
Views
2K
Back
Top