Programming

Program to Read Rupees & Paisa of Each Currency Using Structure

Write a Program to read Rupees & paisa of each currency using structure. Pass the two currency as function argument to add the two currency. (Note that if paisa>=100 then it will be 1 Rupees)

Source Code

#include<iostream.h>
#include<conio.h>
typedef struct
{
 int rup;
 int pai;
 }cur;
 
 cur sum(cur a,cur b)
 {
  cur c;
  c.rup=a.rup+b.rup;
  c.pai=a.pai+b.pai;
  while(c.pai>=100)
  {
   c.pai-=100;
   c.rup+=1;
   };
   return c;
   }
 
void main()
{
  clrscr();
  cur c1,c2,c3;
  cout<<"Enter rupees of 1st currency: ";
  cin>>c1.rup;
  cout<<"Enter paisa of 1st currency: ";
  cin>>c1.pai;
  cout<<"Enter rupees of 2nd currency: ";
  cin>>c2.rup;
  cout<<"Enter paisa of 2nd currency: ";
  cin>>c2.pai;
  c3=sum(c1,c2);
  cout<<"The sum is"<<endl<<"Rupees= "<<c3.rup<<"Paisa= "<<c3.pai<<endl;;
  getch();

}

Tuts

About Author

Tutsmaster.org provides tutorials related to tech and programmings. We are also setting up a community for the users and students.