Mod down by integer : modulus operator « Operators statements « C++ Tutorial






#include <iostream>

using namespace std;

int main()
{  
   cout << "How many pennies do you have? ";
   int pennies;
   cin >> pennies;
   
   cout << "How many nickels do you have? ";
   int nickels;
   cin >> nickels;

   cout << "How many dimes do you have? ";
   int dimes;
   cin >> dimes;

   cout << "How many quarters do you have? ";
   int quarters;
   cin >> quarters;

   int value = pennies + 5 * nickels + 10 * dimes 
      + 25 * quarters;
   int dollar = value / 100;
   int cents = value % 100;

   cout << "Total value = " << dollar << " dollar and "
      << cents << " cents\n";

   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