I have a project due in a programming class at the college today.
I have know idea how to begin. The project is in C++, and I have a compiler that I borrowed from the school and loaded onto my computer. The project says that I have to come up with some amount of money that is less than 100\$. Then it has to loop until it gets to zero. When it gets to zero the project must then terminate. This is basic programming but I have no clue how to do this could anyone please help.

Thanks,
Kyle

2. Considering that it's an assignment, I'm sure the professor didn't spring this on you suddenly. You might have wanted to start sooner. Further, you didn't reguritate enough of the assignment to even know where to start. Since it's a class, I'm sure the professor believes that he's taught enough for you to be able to do the assignment. Good luck with that.

A good place to start would be an int main()
Code:
```int main()
{
//do stuff
return 0;
}```

3. No he didnt spring this on me suddenly but shen I loaded the compiler onto my computer my hard drive died so we had to fix that. I have to figure out a way to come up with that amount using the least amount of bills and coins. But any help would be appreciated.

4. Google is your friend. If it's the algorithm you're having difficulty with, look there.

If it's programming that you're having difficulty with, post what you've got, and we'll try to help.

5. Straight-forward (but not necesarily ideal, if the coin values are trickily chosen) method is to have the coin values in an array, sorted from greatest to smallest value. Then you walk through the array, substracting the coin value from the total until it won't fit anymore, tracking the count. Then you step to the next coin value and repeat.
Pseudocode:
Code:
```int coin_values[] = { 50, 20, 10, 5, 2, 1 };
int money = random(between 50 and 100);
int coin_usage[coin_values.length] = {0};

for(i = 0; i < coin_values.length; ++i) {
while(money > coin_values[i]) {
++coin_usage[i];
money -= coin_values[i];
}

print("Coins used:\n");
for(i = 0; i < coin_values.length; ++i) {
print(coin_values[i] + ": " + coin_usage[i] + "\n");
}```

6. Ha. That's hardly pseudo-code. After just a few adjustments, that's working code. Anyway, can you explain the part you mentioned about "if the coin values are trickily chosen"? What values would be tricky?

7. Can't remember exactly, but I believe when both the 3 and 2 coins exist, it's possible not to have the ideal amount.

But perhaps this is only when there's no 1 coin.

E.g. Coin values are 1, 5, 20, 30 and 50. Money is 60. Using my algorithm, you need 3 coins (50 + 5 + 5), but the ideal way uses 2 (30 + 30).

8. Originally Posted by CornedBee
Pseudocode:
Code:
```int coin_values[] = { 50, 20, 10, 5, 2, 1 };
int money = random(between 50 and 100);
int coin_usage[coin_values.length] = {0};

for(i = 0; i < coin_values.length; ++i) {
while(money > coin_values[i]) {
++coin_usage[i];
money -= coin_values[i];
}

print("Coins used:\n");
for(i = 0; i < coin_values.length; ++i) {
print(coin_values[i] + ": " + coin_usage[i] + "\n");
}```
Pseudocode is a generic way of describing an algorithm without use of any specific programming language syntax.
http://en.wikipedia.org/wiki/Pseudocode

9. You can't have code, even pseudo-code, without intentionally or unintentionally following at least a bit the syntax of some programming language.

This said, my pseudo-code always looks extremely C-like - it's what I'm most comfortable with.

10. Pseudocode V2.1

create an array for coin values
create and initialize an array with the same amount of elements as the array of coin values to count how many times each coin was used

retrieve the amount of money (random number 50..100?)

loop through the array of coin values
for each coin value, while the money is greater than the current coin value, add one to the coin usage array index that represents that coin value and subract the amount from the total amount of money

output the values array next to the usage array and you're done

11. That's an algorithm description, not pseudocode.

And never mind that the Wikipedia says that's exactly what pseudocode is...

12. Originally Posted by CornedBee
That's an algorithm description, not pseudocode.
okay then...

13. go and read the loop part from the tutorials!!

ur gonna see that it very very very easy!!!

14. Originally Posted by CornedBee
Can't remember exactly, but I believe when both the 3 and 2 coins exist, it's possible not to have the ideal amount.

But perhaps this is only when there's no 1 coin.

E.g. Coin values are 1, 5, 20, 30 and 50. Money is 60. Using my algorithm, you need 3 coins (50 + 5 + 5), but the ideal way uses 2 (30 + 30).
Ah, of course. I came up with something similar while I was at lunch. Coin values of 4, 3, and 1, trying to make change for 6. Ideal is 2 coins (3 + 3), but the algorithm uses 3 (4 + 1 + 1). Seems like an interesting problem to solve.