Originally Posted by
tabstop
You should search (using whatever search mechanism you like) for either "mod" or "modulus" or "% in C" or something similar.
I have done some googling on the topic but nothing I feel is helping. I found this earlier, see what I put after and let me know if I am o the right track, I believe that is C++ so I will change some of it to make it what I know to be C
Code:
#include <iostream>
int main()
{
int num;
cin >> num;
// num % 2 computes the remainder when num is divided by 2
if ( num % 2 == 0 )
{
cout << num << " is even ";
}
return 0;
}
Here is kind of what I am thinking, trustme I am new and at work so I don't have my compiler in front of me or the projects we have done to reference.
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
float amtDue = 0;
float amtGiven = 0;
float balAmount =0;
float twenty = 20.00
float ten = 10.00;
float five = 5.00;
float one = 1.00;
float quarter = .25;
float dime = .10;
float nickel = .05;
float penny = .01;
printf ("Enter the Amount Due: ");
scanf ("%f", &amtDue);
printf ("Enter the Amount Given: ");
scanf ("%f", &amtGiven);
balAmount = amtDue - amtGiven;
printf ("Change Due: $ %f", balAmount);
// This is where I really don't know the code but put what my best idea is something like
float modTwenty = amtbalance % twenty;
float modTen = modTwenty % ten;
// and so on down the line, I can figure out the float or int once I am behind my compiler
// I am using float because I am using MOD and want the result to be true, then using %d to printf the int so it doesn't say something like 2.3 twenties which is impossible
printf ("Twenties: %d \nTens: %d", modTwenty, modTen);
system ("pause");
return 0;
}
Am I getting on the right path???
i would expect the out put at the end to say something like
Twenties: 2
Tens: 1
and so on...
Thanks