well this is really quick pseudo code that i just made. it should work. dont know exactly how u did it, or if this even contrasts your original approach, but if i was at ACM, thats the way i would do it.
Code:
var total...pennies : integer;
if( total>199 )then
inc toonies by floor( total/200.0 )
total= total - (toonies*200)
if( total>99 )then
inc loonies by floor( total/100.0 )
total= total - (loonies*100)
if( total>24 )then
inc quarters by floor( total/25.0 )
total= total - (quarters*25)
if( total>9 )then
inc dimes by floor( total/10.0 )
total= total - (dimes*10)
if( total>4 )then
inc nickel by floor( total/5.0 )
total= total - (nickel*5)
if( total>0 )then
inc pennies by floor( total/1.0 )
total= total - (pennies*1)
code i quickly wrote in simba:
Simba Code:
program new;
var
total,a,b,c,d,e,f: integer;
begin
total:= 1235;
if( total>199 )then
incEx( a , floor( total/200.0 ));
total:= total - (a*200);
if( total>99 )then
incEx( b , floor( total/100.0 ));
total:= total - (b*100);
if( total>24 )then
incEx( c , floor( total/25.0 ));
total:= total - (c*25);
if( total>9 )then
incEx( d , floor( total/10.0 ));
total:= total - (d*10);
if( total>4 )then
incEx( e , floor( total/5.0 ));
total:= total - (e*5);
if( total>0 )then
incEx( f , floor( total/1.0 ));
total:= total - (f*1);
writeln(tostr(a));
writeln(tostr(b));
writeln(tostr(c));
writeln(tostr(d));
writeln(tostr(e));
writeln(tostr(f));
end.
and c++ code of my pseudo code since u insist this is wrong (post 4)...
Code:
#include <cmath>
#include <iostream>
using namespace std;
int main(){
int total;
int a=0,b=0,c=0,d=0,e=0,f=0;
total= 1235;
if( total>199 ){
a= a + floor( total/200.0 );
total= total - (a*200);
}
if( total>99 ){
b= b + floor( total/100.0 );
total= total - (b*100);
}
if( total>24 ){
c= c + floor( total/25.0 );
total= total - (c*25);
}
if( total>9 ){
d= d + floor( total/10.0 );
total= total - (d*10);
}
if( total>4 ){
e= e + floor( total/5.0 );
total= total - (e*5);
}
if( total>0 ){
f= f + floor( total/1.0 );
total= total - (f*1);
}
cout << a << endl;
cout << b << endl;
cout << c << endl;
cout << d << endl;
cout << e << endl;
cout << f << endl;
cin.get();
return 0;
}