Thursday, October 16, 2014

If...else condition example program in C++


Prog 4 : Write a program for an electricity for charges the following to users and find the total bill.
1.  for the first 100 units 60 paisa per unit.
2.  for next 200 units 80 paisa per unit.
3.  except from this are 90 paisa per unit.



#include<iostream.h>
#include<conio.h>
void main()
{
int unit;
float rs;
cout<<"\n enter the number of units.";
cin>>unit;
if(unit>=300)
{
unit=unit-300;
rs=(unit*0.90)+220;
}
else if(unit>=100 && unit<=300)
{
                             unit=unit-100;

                             rs=(unit*0.80)+60;

                                 }
                         else

                         {

                           rs=unit*0.60;
                   }
                          cout<<"Rupees ="<<s;
                             getch();

          }


Output:

enter the number of units.500
Rupees =400

No comments: