เรางงตรงนี้มากค่ะ
a=money/1000;
money=money00;
เราคิดเป็นแบบตัวเลขคณิตจริงๆแล้วมันประหลาด ถ้ารับเงินมา 8600 หารด้วย 1000 จะเท่ากับ 8.6
% คือหารเอาเศษ ถ้าหาร 8600 ก็จะเท่ากับ 600 แล้วทำไมพอรันออกมาถึงได้ 8 ?
ขออภัยสำหรับคำถามโง่ๆนะคะ กำลังหัดอยู่ T___T;
##ตัวอย่างโค้ดค่ะ##
#include<stdio.h>
int main()
{
int money,a;
printf("The ATM has only 100 , 500 and 1000\n");
printf("Enter amount of money : ");
scanf("%d",&money);
if (money % 100 == 0)
{
if (money/1000!=0)
{
a=money/1000;
money=money % 1000;
printf("Amount of 1000 Baht is %d\n",a);
}
if (money/500!=0)
{
a=money/500;
money=money%500;
printf("Amount of 500 Baht is %d\n",a);
}
if (money/100!=0)
{
a=money/100;
money=money % 100;
printf("Amount of 100 Baht is %d\n",a);
}
}
else
{
printf("Cannot withdraw money");
}
}
ช่วยอธิบายภาษา C ข้อนี้หน่อยค่ะ
a=money/1000;
money=money00;
เราคิดเป็นแบบตัวเลขคณิตจริงๆแล้วมันประหลาด ถ้ารับเงินมา 8600 หารด้วย 1000 จะเท่ากับ 8.6
% คือหารเอาเศษ ถ้าหาร 8600 ก็จะเท่ากับ 600 แล้วทำไมพอรันออกมาถึงได้ 8 ?
ขออภัยสำหรับคำถามโง่ๆนะคะ กำลังหัดอยู่ T___T;
##ตัวอย่างโค้ดค่ะ##
#include<stdio.h>
int main()
{
int money,a;
printf("The ATM has only 100 , 500 and 1000\n");
printf("Enter amount of money : ");
scanf("%d",&money);
if (money % 100 == 0)
{
if (money/1000!=0)
{
a=money/1000;
money=money % 1000;
printf("Amount of 1000 Baht is %d\n",a);
}
if (money/500!=0)
{
a=money/500;
money=money%500;
printf("Amount of 500 Baht is %d\n",a);
}
if (money/100!=0)
{
a=money/100;
money=money % 100;
printf("Amount of 100 Baht is %d\n",a);
}
}
else
{
printf("Cannot withdraw money");
}
}