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

×

What is the problem in this atm program

include<iostream.h>

#include <conio.h>
#include<iomanip.h>
void calculate(double &y, double x);
main()
{
clrscr();
double y,x=0.00;
int ch=0;

do
{
cin>>y;
if (y<=2000.00)
{
do
{
cin>>x;
double z=x;
if(((int)z%5==0)&&(y>x+0.50))
{
calculate(y,x);
}
else if(x>=y+0.50)
{
cout<<"Invalid";
x=0.00;
}
else
{
cout<<"Try again:";
x=0.00;
}
}
while(x==0.00);
}
else
{
cout<<"Invalid!";
ch=1;
}
}
while (ch==1);
getch();
return 0;
}
void calculate(double &y, double x)
{
y=y-x-0.50;

cout<<"\nYour current balance is: "<<setprecision(2)<<y;
}

asked 29 Nov '14, 21:45

hellobrother's gravatar image

0★hellobrother
252
accept rate: 0%


you shold use #include<iostream> instead of #include<iostream.h> no need to add if(n>0 && n<=2000) and if(st>=0 && st<=2000) and finally in if(n%5==0 && n<st) it should be (n+0.50<2000)

link

answered 29 Nov '14, 21:49

gagan1998_oct's gravatar image

1★gagan1998_oct
1713
accept rate: 15%

Do not print what you are not asked for also:

"Your current balance is:"
link

answered 29 Nov '14, 21:55

betlista's gravatar image

3★betlista ♦♦
16.9k49115225
accept rate: 11%

Try this kind of a format for your program

include<iostream>

•using namespace std;

•int main()

•{

•double y;

•int x;

•cin>>x;

•cin>>y;

•if (x+0.50<y && x%5==0)

•{

•cout<<y-x-0.50;

•}

•else

•cout<<y;

•}

link

answered 29 Nov '14, 21:50

gagan1998_oct's gravatar image

1★gagan1998_oct
1713
accept rate: 15%

Very bad formatting...

(29 Nov '14, 21:53) betlista ♦♦3★

conio.h is a non-recommended header file,
Standard way of writing a cpp program is bit different,
Refer this link i have made some changes
http://ideone.com/3YUGsP

link

answered 29 Nov '14, 21:52

rishabhprsd7's gravatar image

2★rishabhprsd7
1.9k11243
accept rate: 14%

avoid using conio.h, clrscr(), getch().

(29 Nov '14, 21:54) rishabhprsd72★
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:

×966
×690
×190
×150
×131
×30
×19
×19

question asked: 29 Nov '14, 21:45

question was seen: 933 times

last updated: 29 Nov '14, 21:55