I'm making a "project" for university. Short program that will exchange any sum of money to coins, valued from 1 to 0,01 .
#include <iostream>
using namespace std;
int main()
{
double C;
int rest;
cout << "Wpisz kwote w zl. " << endl;
cin >> C;
double c1=1 ,c2=0.75 ,c3=0.50 ,c4=0.20 ,c5=0.10 ,c6=0.05 ,c7=0.02 ,c8=0.01;
int coin1=c1*100 ,coin2=c2*100 ,coin3=c3*100 ,coin4=c4*100 ,coin5=c5*100 ,coin6=c6*100 ,coin7=c7*100 ,coin8=c8*100;
int ile1=0, ile2=0, ile3=0, ile4=0, ile5=0, ile6=0, ile7=0, ile8=0;
int cash= C*100;
double check;
if (cash-coin1>=0){rest=cash%coin1;ile1= cash/coin1; cash = rest; }
cout << cash << " " << 28083%coin1 ;
if (cash-coin2>=0){rest=cash%coin2;ile2= cash/coin2; cash = rest; }
cout << cash << endl;
if (cash-coin3>=0){rest=cash%coin3;ile3= cash/coin3; cash = rest; }
cout << cash << endl;
if (cash-coin4>=0){rest=cash%coin4;ile4= cash/coin4; cash = rest; }
cout << cash << endl;
if (cash-coin5>=0){rest=cash%coin5;ile5= cash/coin5; cash = rest; }
cout << cash << endl;
if (cash-coin6>=0){rest=cash%coin6;ile6= cash/coin6; cash = rest; }
cout << cash << endl;
if (cash-coin7>=0){rest=cash%coin7;ile7= cash/coin7; cash = rest; }
cout << cash << endl;
check=ile1*c1+ile2*c2+ile3*c3+ile4*c4+ile5*c5+ile6*c6+ile7*c7+ile8*c8;
I know the structure itself is super messy, but I'm learning. I'll try to shorten it later and make it more clear. But that's not my problem.
The problem is that it looks like % operand doesn't work correctly.
When I put in value 280.83 for C, well, the program read cash%coin1 (coin1 being equal to 100 ) as 82. Where did the random 1 go ? Also, just to check, i wrote 28083%coin1 and the results were 837. Weird.
How can I fix this ?
edit:
double C=280.83, c1=1;
int cash = C*100, coin1=c1*100, ile1=0;
rest=cash%coin1;ile1= cash/coin1; cash = rest;
rest = 82. Should be 83.