fork download
  1. #include <stdio.h>
  2.  
  3. float quarterCal(int value);
  4.  
  5. int main(void) {
  6.  
  7. int quarters;
  8. char invalidChar;
  9. float total;
  10.  
  11.  
  12. //get input from users
  13. printf("How many quarters do you have?\n");
  14. if(scanf("%d%c", &quarters, &invalidChar) == 1 || invalidChar == '\n' ){
  15. //Calcuate how many quarters you have
  16. total = quarterCal(quarters);
  17. //print total to user
  18. if(total >= 0){
  19. printf("You have total of $%.2f\n", total);
  20. } else if(total < 0){
  21. printf("How weird... you have a total of $%.2f\n", total);
  22. }
  23.  
  24.  
  25. } else {
  26. printf("Invalid input\n");
  27. }
  28.  
  29. return 0;
  30. }
  31.  
  32. float quarterCal(int value){
  33. return value*0.25;
  34. }
Success #stdin #stdout 0s 9432KB
stdin
10
stdout
How many quarters do you have?
You have total of  $2.50