I'm having a problem with a class assignment and was hoping to get some help, as I'm at a loss. Please help! The following is the assignment:
The program should do the following:
•Ask how many coupons are being redeemed.
•Determine from the number of coupons which prizes should be given. For example, if I redeem 156 coupons, I should receive: 2 water pistols, and a piece of jewelry but no stuffed animals or PopRocks. Output the results to the employee in an easy to understand way.
- Do not ask the customer what prize they want! -
•Determine how many coupons should be left over. In the above example, after receiving all the prizes I should still have 1 coupon left. Let the employee know that too.
I must use loops, and its suggested I use the "while" loop.
Stuffed animals cost 200 coupons
Water pistols cost 75 coupons
Pop Rocks cost 35 coupons
Jewelry costs 5 coupons
This is what I have so far and even this isn't working:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int coup = 0, animal = 200, pistol = 75, rox = 35, jewl = 5, total = 0;
cout << "How many coupons has the customer earned? ";
cin >> coup;
do
{
cout << "\n\nYou have earned a stuffed animal!" << endl;
total = coup - animal;
cout << "You have " << total << " coupons remaining.\n\n";
animal++;
} while (coup >= 200);
You need code tags and indentation. Look it up before you ask what it is, if you don't recognize those terms.
OK, let me see what you have so far. Chances are, instead of referring to the variable animal when subtracting, you should subtract 200 straight out, or define a constant. You increment that variable afterwards - is the coupon price of the animal supposed to change? I can't say since this isn't my homework but I doubt that's the plan. Set the animal/pistol/etc counts to 0 and define constants for the coupon costs instead or just refer to the integer literal directly.
Second, you should use a while loop and not a do while. What if the player has 100 coupons? They will still go into the do while loop because you go into a do while loop AT LEAST ONCE, in ALL cases.
Once you clear the do while loop, you know that the customer has less than 200 tickets. So now you can just repeat the process, subtracting a smaller number of tickets and incrementing a different prize count, etc.
you really dont need to use any library here except the iostream... well any way anyone can use any library ahehehe!!!! its just its the only library taught to us... have i done great here sir?
if you got some problem just search for my facebook acct. dont expect for me in terms of using other library than <iostream> maybe i can help you out with algorithms...
Ok, this is what my instructor suggests, followed by what I have so far(which doesn't seem to work the way I want it to). I'm just learning this, so forgive my ignorance.
1. Ask for and receive input on how many coupons the customer has.
2. Begin the logic to determine what prizes to give. Start with a while loop that runs as long as there are more than 200 coupons.
a. If there are more than 200 coupons, increment a stuffed animal counter and subtract 200 from coupon total.
b. Next, if there are more than 100 coupons, increment a water pistol counter and subtract 100 from coupon total.
c. I think you know what’s next…
3. Output all counters and the remaining coupons with informative messages.
4. Test, test, test! Run your program using 1,000 coupons. Now, run it using 1. Did it work the way it should?
{
int coup = 0;
int ani = 0;
int pis = 0;
int rox = 0;
int jew = 0;
cout << "How many coupons has the customer earned? ";
cin >> coup;
while (coup >= 200)
{
coup = coup - 200;
ani++;
cout << "You have won " << ani << " stuffed animal(s)." << endl;
}
ok i get what you want... here is the sample output... i hope this is what yah want...
--------------------------------------------------------------------------------------------------------------------------
How many coupons the costumer earned: 1000
Costumer earned:
0 Jewelry
0 Pop Rocks
0 Water Pistols
5 Stuffed Animals
0 Coupons left for the costumer.
[Q]uit or [C]ontinue:C
How many coupons the costumer earned: 1
Costumer earned:
0 Jewelry
0 Pop Rocks
0 Water Pistols
0 Stuffed Animals
1 Coupons left for the costumer.
[Q]uit or [C]ontinue:q
--------------------------------------------------------------------------------------------------------------------------
and for the code of this here it is:
--------------------------------------------------------------------------------------------------------------------------
#include <iostream>
using namespace std;
int main (){
int coup = 0;
int ani = 200;
int pis = 75;
int rox = 35;
int jew = 5;
char opt;
do {
cout << "How many coupons the costumer earned? ";
cin >> coup;
cout << endl;
int numa = 0;
int nump = 0;
int numr = 0;
int numj = 0;
do {
if (coup >= jew && coup < rox && coup != 0){
coup = coup - jew;
numj += 1;
}
else if ( coup >= rox && coup < pis && coup != 0){
coup = coup - rox;
numr += 1;
}
else if ( coup >= pis && coup < ani && coup != 0){
coup = coup - pis;
nump += 1;
}
else if ( coup >= ani && coup != 0){
coup = coup - ani;
numa += 1;
}
else if ((coup < jew && coup > 0)||(coup == 0)){
break;
}
} while ( coup > 0 );
cout << "Costumer earned: " << endl;
cout << numj << " Jewelry" << endl;
cout << numr << " Pop Rocks" << endl;
cout << nump << " Water Pistol(s)" << endl;
cout << numa << " Stuffed Animal(s)" << endl << endl;
cout << coup << " coupons left for the costumer." << endl;
cout << "[Q]uit or [C]ontinue: ";
cin >> opt;
} while (toupper (opt == 'c'));
return 0;
}
--------------------------------------------------------------------------------------------------------------------------
and ignorant??? all of us are ignorant in this language no one can use c++ to its fullest even the one who made it cant use its fullest... and i know something that you dont know and you know something i dont know... i'll be needin yah help too someday... yah IT student?
what am i to do?????? in the source code if your smart enough you'll understand the algorithm behind it... am i ryt sir? but as you requested i am to give you a brief description or explanation on my code...
first i set the value of coupon to 0 for its default value and set the prizes value as well.
then whenever i asked for the number of coupons i made a do while loop and inside it i set the value of the numbers of prizes to be received by the costumer. then i made an inner do while loop that will determine what prize will be given to the costumer... i set some conditions using if else statements and in the statement there happened the subtraction of coupon and in there a counter for prizes counts... if it met the condition then it will run the operation in the statement... then after that... it will perform the operation for the remaining coupons...
im not that good in explaining... im havin a hard time explainin it...
If you can't explain it at all, better to just be quiet than to give the answer to the OP without any discussion. After all, (and I know how cheesy this is but this is how it works here) if you just give someone the answer, how do they learn?
And I wouldn't say that explanation was that bad. It was certainly livable.
I'll assume this sentence is supposed to mean "no one knows every aspect of C++", because otherwise it's completely false (it's still not true, but it's at least closer).
even the one who made it cant use its fullest
You have obviously never seen a language lawyer. There's people out there who know C++ so well, it's creepy.
Posting complete code doesn't help anyone. It doesn't help you, because you're doing someone else's work for nothing, and it doesn't help the one asking the question because learning is about getting to the answer, not about having the answer.
Pushing them in the right direction is always far better than telling them what to do.
really??? upon our studies on the history of C++ the creator of it didnt "know every aspect of c++" or havent used all the library to its fullest... and now gimme how my algo works???? and now tell me jah get it... and now if im not helpin him out... atleast i have practiced my skills...
yah they didnt just know c++ but never mastered ALL the libraries... all i know there's a lot of libraries of c++... now show me a program by language lawyer who have used all libraries in c++... and only the i'll believe in u