Na začiatku maš zadať sumu ktoru maš zaplatiť potom zadaš bankovky, sčita bankovky a vyda ti tiež v bankovkach.
Neviete prečo mi neide tá podmienka, aby suma bola vačšia ako 0 a menšia ako 10000 ? Keď dam vačšie čislo jak 10000 tak nevypiše že vrong imput ale pokračuje ďalej.
DAKUJEM
Program:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/*
*
*/
double zaokruhli(double x)
{
int temp = floor(100*x +0.5); //double na int
return (double)temp/100; //z int na double
}
int main(int argc, char** argv) {
double h,i,x = 100;
double vydavok[100];
double suma = 0;
double vlozene = 0;
int a = 0,c=0;
int abcint,b,d,e,f;
double abc;
printf("Enter value of your bill: ");
scanf("%lf", &suma);
if(suma > 10000 || suma < 0){
printf("Wrong input! ");
getch();
return 0;
}
printf("Insert money for payment: ");
while(h > 0){
scanf("%lf", &h);
if(h == 0.01 || h == 0.02 || h == 0.05 || h == 0.1 || h == 0.2 || h == 0.5 || h == 0.1 || h == 1 || h == 2 || h == 5 || h == 10 || h == 20 || h == 50 || h == 100 || h == 0 ){
}else{
f=h;{
if(h-f==0)printf("%.0f is invalid!\n ", h);
else
printf("%.2f is invalid!\n ", h);
}
system("PAUSE");
return 0;
}
vlozene = vlozene + h;
}
{
d=vlozene;
if(vlozene-d==0) printf("You have inserted: %.0lf ",vlozene);
else printf("You have inserted: %.2lf ",vlozene);
}
if(suma > vlozene){
printf("\nNot enough money!\n ");
system("PAUSE");
return 0;
}
abc=vlozene-suma;
abcint=abc;
e=vlozene-suma;
if(abc-abcint==0) printf("\nTo return: %.0lf",abc);
if(abc-abcint!=0) {
if (e==0) printf("\nTo return: %.0lf",abc);
else printf("\nTo return: %.2lf",abc);
}
vlozene =zaokruhli(vlozene);
suma =zaokruhli(suma);
suma = suma+0.001;
//suma = Truncate(suma * 1000) / 1000suma;
i = vlozene - suma;
i = zaokruhli(i);
do{
if(i >= x){
vydavok[a] = x;
i= i-x;
a++;
i = zaokruhli(i);
}
while (1){
if(i>=100){x= 100; break;}
else if(i>=50){x= 50; break;}
else if(i>=20){x= 20; break;}
else if(i>=10){x= 10; break;}
else if(i>=5){x= 5; break;}
else if(i>=2){x= 2; break;}
else if(i>=1){x= 1; break;}
else if(i>=0.5){x= 0.5; break;}
else if(i>=0.2){x= 0.2;break;}
else if(i>=0.1){x= 0.1; break;}
else if(i>=0.05){x= 0.05; break;}
else if(i>=0.02){x= 0.02; break;}
else if(i>=0.01){x= 0.01; break;}
else if(i < 0.01){ break;}
}
}while(i > 0.00999);
if(a!=0) {
printf("\nCollect your payback: ");
for(c; c < a; c++){
b=vydavok[c];
if(vydavok[c]-b==0) printf("%.0lf ", vydavok[c]);
else printf ("%.2lf ", vydavok[c]);
}}
printf("\n");
return 0;
}