Sep 30, 2014 at 12:46am
what does this (%) stand for i have 2 different codes with it in there cna u tell me what it means in both codes thanks
1 2 3 4
|
//this is my random number gen my teacher showed me but i
//dont know what the (%) means
int num = rand()%201-100;
|
and
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
int main(int argc, char** argv) {
// Constant variables for change
const int DOLLAR = 100;
const int QUARTER = 25;
const int DIME = 10;
const int NICKEL = 5;
const int PENNY = 1;
string input;
do
{
// Change problem
// User input
cout << "Enter owed amount: ";
double owedAmount;
cin >> owedAmount;
cout << "Enter the tender: ";
double amountPaid;
cin >> amountPaid;
double change = amountPaid - owedAmount;
// Convert my change to an integer to use
// the modulus operator]
// Add an offset to the change
int intChange = (change + .005) * 100;
cout << "Your change is: " << intChange << endl;
int numDollars = intChange / DOLLAR;
// Get the remaing amount of change
intChange %= DOLLAR;
int numQuarters = intChange / QUARTER;
intChange %= QUARTER;
int numDimes = intChange / DIME;
intChange %= DIME;
int numNickels = intChange / NICKEL;
intChange %= NICKEL;
int numPennies = intChange / PENNY;
intChange %= PENNY;
cout << "Number of dollars: " << numDollars << endl;
cout << "Number of quarters: " << numQuarters << endl;
cout << "Number of dimes: " << numDimes << endl;
cout << "Number of nickels: " << numNickels << endl;
cout << "Number of pennies: " << numPennies << endl;
cout << "Do you want to enter again?: ";
cin >> input;
}while(input == "yes");
return 0;
}
|
Last edited on Sep 30, 2014 at 12:47am
Sep 30, 2014 at 1:10am
ya it makes sense thanks for the help shadow
Last edited on Sep 30, 2014 at 1:11am