You are not logged in. Please login at www.codechef.com to post your questions!

×

atm problem need help

#include <stdio.h>
#include <stdlib.h>

#ifndef BANK_CHARGE
#define BANK_CHARGE  0.5
#endif;

int main (int argc, char **argv){
// if(argc != 3){
//   printf("Usage: %s [int] [float]\n", argv[0]);
//   exit(1);
// }

int withdraw = atoi(argv[1]);
float balance = atof(argv[2]);

if((withdraw % 5) != 0){
printf("%.2f", balance);
exit(1);
}
if(withdraw > 2000 || withdraw == 0){
printf("%.2f", balance);
exit(1);
}

float totalWithdraw = (withdraw + BANK_CHARGE);

if(totalWithdraw >= balance){
printf("%.2f", balance);
exit(1);
}

printf("%.2f", balance - totalWithdraw);
return 0;
}

this is my code and its showing runtime error

asked 17 Aug '14, 23:51

n1a24's gravatar image

0★n1a24
1
accept rate: 0%

edited 17 Aug '14, 23:57

kcahdog's gravatar image

3★kcahdog
10.0k2854129


Hi @n1a24. The arguments to your code should be taken by using scanf and they are not given as argumments to main function as you have taken. Just change your main to int main() and take input as scanf("%d %f",withdraw, balance);

link

answered 18 Aug '14, 00:00

kcahdog's gravatar image

3★kcahdog
10.0k2854129
accept rate: 14%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×190

question asked: 17 Aug '14, 23:51

question was seen: 660 times

last updated: 18 Aug '14, 00:00