loops - Change Calculation Program in C -


i'm beginning studying programming , trying write program display how many of each denomination of currency required given amount of change. i'm studying in japan, currency yen, think basic code universal. i've seen other similar programs online, mine has few features may cause of problem, i'm not sure.

first user inputs whether or not there two-thousand yen bills in register or not. (as these bills not common). enter total amount due. enter how paid. calculates change , how of each denomination , displays it.

however, after enter amount paid, cursor goes next line , sits there indefinitely. don't know what's causing this. guess it's getting stuck in loop somewhere.

does see problem? (*i switched text printed english)

#define _crt_secure_no_warnings  #include <stdio.h>  int main(void) {     //入力     int aru;      printf("are there 2-thousand yen bills in register?\n 1.) yes\n 2.) no\n "); //レジに2千円札が入ってますか?\n 1.) 入ってます\n 2.)入ってません     scanf("%d", &aru);      int total, paid;      printf("enter total price  ");//お会計を記入して下さい。      scanf("%d", &total);     printf("enter amount paid ");//お客さんのお支払った合計を記入してください。     scanf("%d", &paid);      //計算     if (paid < total)     {         printf("insufficiant amount paid\n");//お金を十分にもらいませんでした     }     if (paid > total)     {     int change = paid - total;     int ichi = 0, go = 0, ju = 0, goju = 0;     int hyaku = 0, gohyaku = 0, sen = 0, nisen = 0, gosen = 0;      while (change > 5000)     {         change - 5000;         gosen++;     }     while (change > 2000)     {         if (aru == 1)         {             change - 2000;             nisen++;         }         else         {             nisen = 0; //skips calculating 2000 yen bills if answer 'no'         }     }     while (change > 1000)     {         change - 1000;         sen++;     }     while (change > 500)     {         change - 500;         gohyaku++;     }     while (change > 100)     {         change - 100;         hyaku++;     }     while (change > 50)     {         change - 50;         goju++;     }     while (change > 10)     {         change - 10;         ju++;     }     while (change > 1)     {         change - 1;         ichi++;     }      //出力     printf(" %d \n", gosen);     printf(" %d \n", nisen);     printf(" %d \n", sen);     printf(" %d \n", gohyaku);     printf(" %d \n", hyaku);     printf(" %d \n", goju);     printf(" %d \n", ju);     printf(" %d \n", go);     printf(" %d \n", ichi); }     return 0; }  

while (change > 5000) //this infinite loop  {     change - 5000; //no change made change     gosen++; } 

you might want change -= 5000; instead of change - 5000; @ several places in code. change-=5000 equivalent to

 change = change-5000; 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -