Hi guys! I'm very new to coding (as in I can write the "Hello World!" program and a few other basic things.) For homework, we have to practice writing different programs. I've done all of them fairly easily but am stuck on the last one. Any hints you can give me? (Not looking for the full code to be done for me, just looking for an explanation or some hints!)
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
usingnamespace std;
int main ()
{
int cen, dol, qua, dim, nic, pen, left_over;
cout << "Enter a number of change: ";
cin >> cen;
}
Generally start by mapping out on paper what you want to happen. In this case you ask for input in cents. So if someone were to type in for example 103 we know that the out put we want is 1 dollar and 3 pennies.
Your program should assign an int value to each type of money. A dollar is worth 100 for example. You can create a loop that checks first if the input value is greater than 100. If so subtract 100. A counter variable get increased by 1. We know we have at least 1 dollar. Run through the loop again. Is the value still greater than 100? No... Well then we only have one dollar. End loop.
Only 3 left.
Repeat this pattern down through the money values. Quarters, dimes, and nickels are all too big. Only three pennies left.