Read int type variables and calculate mod value : modulus operator « Operators statements « C++ Tutorial






#include <iostream>
#include <string>
using namespace std;
int main(void)
{
   int total, dollars, quarters, dimes, nickels, leftover;
   cout << "Enter number of pennies to make change for: ";
   cin >> total;
   dollars = total / 100;
   leftover = total % 100;
   quarters = leftover / 25;
   leftover %= 25;
   dimes = leftover / 10;
   leftover %= 10;
   nickels = leftover / 5;
   leftover %= 5;
   cout << "Dollars: " << dollars << endl;
   cout << "Quarters: " << quarters << endl;
   cout << "Dimes: " << dimes << endl;
   cout << "Nickels: " << nickels << endl;
   cout << "Pennies: " << leftover << endl;
   return 0;
}








3.5.modulus operator
3.5.1.The modulus operator.
3.5.2.Mod down by integer
3.5.3.Modular operator
3.5.4.Read int type variables and calculate mod value