943,840 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1314
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 3rd, 2008
0

a little help please

Expand Post »
so im working on my assignment and it says

Percentage of ticket revenue which goes to administrative costs. This input will be entered in percent format (see sample runs below); your program must convert this to a decimal fraction. For example, the user enters 25% as 25, not .25; you convert the 25 to .25 in your code.

how do i conver for example 25 to .25??
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
anbuninja is offline Offline
61 posts
since Mar 2008
Oct 3rd, 2008
0

Re: a little help please

Click to Expand / Collapse  Quote originally posted by anbuninja ...
so im working on my assignment and it says

Percentage of ticket revenue which goes to administrative costs. This input will be entered in percent format (see sample runs below); your program must convert this to a decimal fraction. For example, the user enters 25% as 25, not .25; you convert the 25 to .25 in your code.

how do i conver for example 25 to .25??
How about dividing 25 by 100?
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,375 posts
since Jan 2008
Oct 3rd, 2008
0

Re: a little help please

hmmm im really stuck

so this is what we need to do

This program will take user input in the following order:

Number of tickets sold.

Percentage of ticket revenue which goes to administrative costs. This input will be entered in percent format (see sample runs below); your program must convert this to a decimal fraction. For example, the user enters 25% as 25, not .25; you convert the 25 to .25 in your code.

Total amount of prize money distributed.

Name of charity. The name may consist of more than one word (that is, have embedded spaces).

The program then will output the following information in the following order:

Name of charity.

Total revenue generated from the ticket sales. The price of each ticket is currently fixed at $5.00.

Total amount of administrative overhead.

Total amount of prize money overhead.

Balance remaining for the charitable fund


example run

How many tickets were sold? 50000
What percentage of the ticket revenue goes to administrative costs? 2
How much total money is distributed in prizes? 15000
What is the name of the charity? Good Intentions

Charity: Good Intentions
Revenue generated from ticket sales: $ 250000.00
Amount deducted for administrative overhead: $ 5000.00
Amount deducted for prize money: $ 15000.00
Balance raised for charitable fund: $ 230000.00



thats all i got so far >,<, any help? im lost

C++ Syntax (Toggle Plain Text)
  1. #include<iostream>
  2. #include<iomanip>
  3. #include<string>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int ticketssold, percentticket, moneyprizes;
  9. string charity;
  10.  
  11. cout <<"1.Number of tickets sold?: ";
  12. cin >> ticketssold;
  13.  
  14.  
  15.  
  16. cout <<"2.What percentage of the ticket revenue goes to administrative costs?: ";
  17. cin >> percentticket;
  18.  
  19. cout <<"3.How much total money is distributed in prizes?: ";
  20. cin >> moneyprizes;
  21.  
  22. cin.ignore();
  23.  
  24. cout <<"4.What is the name of the charity?: ";
  25. getline(cin,charity);
  26.  
  27. cout << left <<"Charity:" << right << setw(50) << charity << endl;
  28. cout << left <<"Revenue generated from ticket sales:" << right
  29.  
  30.  
  31.  
  32. system("pause");
  33. return 0;
  34.  
  35.  
  36. }
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
anbuninja is offline Offline
61 posts
since Mar 2008
Oct 3rd, 2008
0

Re: a little help please

Click to Expand / Collapse  Quote originally posted by anbuninja ...
hmmm im really stuck
First off I agree with VernonDozier, just divide your percentage value by 100 to get a decimal.

Click to Expand / Collapse  Quote originally posted by anbuninja ...
C++ Syntax (Toggle Plain Text)
  1. #include<iostream>
  2. #include<iomanip>
  3. #include<string>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int ticketssold, percentticket, moneyprizes;
  9. string charity;
  10.  
  11. cout <<"1.Number of tickets sold?: ";
  12. cin >> ticketssold;
Where is the variable to contain the value for each ticket sold?? You can't generate a percentage without a value to go along with it.

Click to Expand / Collapse  Quote originally posted by anbuninja ...
C++ Syntax (Toggle Plain Text)
  1. cout <<"2.What percentage of the ticket revenue goes to administrative costs?: ";
  2. cin >> percentticket;
For this you can add another int called percent (or whatever you want and add the following
percent = percentticket / 100;

But again without having an int variable that totals up the actual revenue from ticket sales, the above is pointless.

Click to Expand / Collapse  Quote originally posted by anbuninja ...
C++ Syntax (Toggle Plain Text)
  1.  
  2. cout <<"3.How much total money is distributed in prizes?: ";
  3. cin >> moneyprizes;
  4.  
  5. cin.ignore();
  6.  
  7. cout <<"4.What is the name of the charity?: ";
  8. getline(cin,charity);
  9.  
  10. cout << left <<"Charity:" << right << setw(50) << charity << endl;
  11. cout << left <<"Revenue generated from ticket sales:" << right
You are display text, but not calling up the variables that have your data stored for the ticket sales, that is kinda important to have, otherwise the user will never know the actual answer.
Reputation Points: 32
Solved Threads: 2
Junior Poster in Training
RayvenHawk is offline Offline
77 posts
since Aug 2008
Oct 3rd, 2008
0

Re: a little help please

 #include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
using namespace std;

int main()
{
	int ticketssold, percentticket, moneyprizes, ticketstotal;
	string charity;
	


	
	cout <<"1.Number of tickets sold?: ";
	cin >> ticketssold;

	ticketstotal = 5.00 * ticketssold;
	


	cout <<"2.What percentage of the ticket revenue goes to administrative costs?: ";
	cin >> percentticket;

	


	cout <<"3.How much total money is distributed in prizes?: ";
	cin >> moneyprizes;

	cin.ignore();

	cout <<"4.What is the name of the charity?: ";
	getline(cin,charity);

	cout << left <<"Charity:" << right << setw(50) << charity << endl;
	cout << ticketstotal;



	system("pause");
	return 0;


}

okay i got 1. updated but im still lost in question 2. about the percent.

ohhh and i know at the end i havent called out all the variables i know how to do that its just that im soo stuck in the input.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
anbuninja is offline Offline
61 posts
since Mar 2008
Oct 3rd, 2008
0

Re: a little help please

Click to Expand / Collapse  Quote originally posted by anbuninja ...
okay i got 1. updated but im still lost in question 2. about the percent.

ohhh and i know at the end i havent called out all the variables i know how to do that its just that im soo stuck in the input.
The total admin charges is calculated as follows:

C++ Syntax (Toggle Plain Text)
  1. cout << percentticket/100. * ticketstotal << endl;

Remember to put a decimal point behind the 100 so that the resultant value becomes a floating point instead of an integer.
Reputation Points: 118
Solved Threads: 15
Posting Pro in Training
Denniz is offline Offline
428 posts
since Sep 2008
Oct 5th, 2008
0

Re: a little help please

alright so little by little im completing this program.

heres my updated code

C++ Syntax (Toggle Plain Text)
  1. #include<iostream>
  2. #include<iomanip>
  3. #include<cmath>
  4. #include<string>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int ticketssold, moneyprizes, ticketstotal;
  10. string charity;
  11. float percentticket;
  12.  
  13.  
  14.  
  15. cout <<"1.Number of tickets sold?: ";
  16. cin >> ticketssold;
  17.  
  18. ticketstotal = 5.00 * ticketssold;
  19.  
  20.  
  21.  
  22. cout <<"2.What percentage of the ticket revenue goes to administrative costs?: ";
  23. cin >> percentticket;
  24.  
  25.  
  26. cout <<"3.How much total money is distributed in prizes?: ";
  27. cin >> moneyprizes;
  28.  
  29. cin.ignore();
  30.  
  31. cout <<"4.What is the name of the charity?: ";
  32. getline(cin,charity);
  33.  
  34. cout <<"Charity:" << right << setw(55) << charity << endl;
  35.  
  36. cout <<"Revenue generated from ticket sales:" << right << fixed << setprecision(2) << setw(16) << '$'
  37. << ticketssold * 5 << endl;
  38.  
  39. cout <<"Amount deducted for administrative overhead:" << right << fixed << setprecision(2) << setw(8) << '$'
  40. << percentticket/100. * ticketstotal << endl;
  41.  
  42.  
  43.  
  44. system("pause");
  45. return 0;
  46.  
  47.  
  48. }

now im having issues on calculating these things
Amount deducted for prize money: $ 15000.00
Balance raised for charitable fund: $ 230000.00


and idk why but the setprecision is not working on
Revenue generated from ticket sales: $ 250000.00
it works fine for
Amount deducted for administrative overhead: $ 5000.00

?????
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
anbuninja is offline Offline
61 posts
since Mar 2008
Oct 5th, 2008
1

Re: a little help please

Click to Expand / Collapse  Quote originally posted by anbuninja ...
now im having issues on calculating these things
Amount deducted for prize money: $ 15000.00
Balance raised for charitable fund: $ 230000.00
What's the difficulty in calculating these two items? The first one is straight from the value the user entered, the second was just the total revenue deducting the admin fee & prize money.

Click to Expand / Collapse  Quote originally posted by anbuninja ...
and idk why but the setprecision is not working on
Revenue generated from ticket sales: $ 250000.00
it works fine for
Amount deducted for administrative overhead: $ 5000.00

?????
That's because you are using integers. Alright, put a decimal point behind the number "5" and magic will appears.
Reputation Points: 118
Solved Threads: 15
Posting Pro in Training
Denniz is offline Offline
428 posts
since Sep 2008
Oct 5th, 2008
0

Re: a little help please

alright thanks Denniz
im almost finished just one problem. when i run it instead of getting 230000.00 i get 234998.00 ? im using float now no more int.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
anbuninja is offline Offline
61 posts
since Mar 2008
Oct 5th, 2008
0

Re: a little help please

Click to Expand / Collapse  Quote originally posted by anbuninja ...
alright thanks Denniz
im almost finished just one problem. when i run it instead of getting 230000.00 i get 234998.00 ? im using float now no more int.
That's because you deducted the wrong thing. Instead of deducting the total admin overhead, you deducted the $2 admin fee!

This question is actually very straightforward, apart from the programming syntax, you should also understand the logic behind all these calculations. Understanding of logic doesn't need programming background.
Reputation Points: 118
Solved Threads: 15
Posting Pro in Training
Denniz is offline Offline
428 posts
since Sep 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Intro to headers
Next Thread in C++ Forum Timeline: Input from file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC