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

×

# 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 252
accept rate: 0%

 1 you shold use #include instead of #include no need to add if(n>0 && n<=2000) and if(st>=0 && st<=2000) and finally in if(n%5==0 && n
 1 Do not print what you are not asked for also: "Your current balance is:"  answered 29 Nov '14, 21:55 16.9k●49●115●225 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;

•}

answered 29 Nov '14, 21:50 1713
accept rate: 15%

(29 Nov '14, 21:53)
 0 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 answered 29 Nov '14, 21:52 1.9k●1●12●43 accept rate: 14% avoid using conio.h, clrscr(), getch(). (29 Nov '14, 21:54)
 toggle preview community wiki:
Preview

### Follow this question

By Email:

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

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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