#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;
}
1 Like
you shold use #include 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)
1 Like
Try this kind of a format for your program
#include
•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;
•}
1 Like
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
Do not print what you are not asked for also:
"Your current balance is:"
1 Like
avoid using conio.h, clrscr(), getch().