c - CS50 PSET 1 Greedy -


i new programming , started trying out problem sets on harvard's cs50. appreciate if can point out me why code wrong.

after compiled , run code, there isn't output.

on note, can explain me how "round" works? don't man round on terminal. thanks!


#include <stdio.h> #include <math.h> int main(void) {      printf(" o hai! how change owed?\n");    float change;   change=getfloat();   double round(double change);    int x= change*100;    int i=0;    while(x>25) {      x=x-25;     i++;     return i;   }    while(x>10) {      x= x-10;     i++;     return i;   }    while(x>5) {     x=x-5;     i++;     return i;   }    while(x>1) {     x=x-1;     i++;     return i;   }    printf("%d\n",i);  } 

first thing after input dollars user should multiply 100 right after convert cents , using round function. use

change = round(change) ; 

in code change floating point value need money in integers count number of coins used use round change integer , cannot count number of coins used using floating point value

then: return ; statement should not used in every loop remove each loop.

as, if using in each lopp it'll calculate particular coins , exit program. remove of return i statements , can write return 0 ; after printf("%d\n", i); statement !


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -