악플보다 두려운 무플... C언어 궁금해요~ ^^
아롱별
질문 제목 :C언어 컴파일은 잘 됬는데 이해가지 않는 구문이 있어요~
질문 요약 :1. 함수에서 int, float와 void의 차이점
2.(int), (float) 등 괄호안에 있음과 없음의 차이 및 각각의 역할.
질문 내용 :환율을 변환하는 소스코드입니다. 이해가 가지 않는 부분이 존재해요~
1번 질문입니다.
float exchange(int *to, int *from, float *money, float *USD, float *EUR, float *JPY, float *CNY){
float exch_money = (*money);
switch(*to){
case 0 : exch_money = exch_money*(*USD); break;
case 1 : exch_money = exch_money*(*EUR); break;
case 2 : exch_money = exch_money*(*JPY); break;
case 3 : exch_money = exch_money*(*CNY); break;
}
switch(*from){
case 0: exch_money = exch_money/(*USD); break;
case 1: exch_money = exch_money/(*EUR); break;
case 2: exch_money = exch_money/(*JPY); break;
case 3: exch_money = exch_money/(*CNY); break;
}
printf(Result: %.2f\n,exch_money);
return exch_money;
}
여기서 float로서 함수를 전개하고 있는데요.
값이 실수형이라 int를 쓰지 않은 것은 알겠습니다.
void를 사용할 수는 없나요?
그리고 void와 float의 차이가 궁금해요.
2번 질문입니다.
else if(num==4){
exchmoney = (int)exch_money;
printf(Withdraw:\n);
printf(10000 x %d = %d\n,exchmoney/10000,(exchmoney/10000)*10000);
printf( 5000 x %d = %d\n,(exchmoney%10000)/5000,((exchmoney%10000)/5000)*5000);
printf( 1000 x %d = %d\n,(exchmoney%5000)/1000,((exchmoney%5000)/1000)*1000);
printf( 500 x %d = %d\n,(exchmoney%1000)/500,((exchmoney%1000)/500)*500);
printf( 100 x %d = %d\n,(exchmoney%500)/100,((exchmoney%500)/100)*100);
printf( 10 x %d = %d\n,(exchmoney%100)/10,((exchmoney%100)/10)*10);
printf( 1 x %d = %d\n,(exchmoney%10)/1,((exchmoney%10)/1)*1);
printf(=============\n);
printf(total: %d\n,exchmoney);
(int) 이렇게 괄호안에 int를 넣은 이유는 무엇인가요?
(int)의 역할과 (int)을 넣지 않았을 때와의 차이점은 무엇인가요?