Program to add 2 distances & show sum as new distance, C/C++ Programming


 THIS PROGRAM IS TO ADD TWO DISTANCES & SHOW THEIR SUM AS NEW DISTANCE


# include
# include

typedef int dist;

struct distance
  {
  dist inch;
  dist feet;
  };
distance add(distance d1,distance d2)
   {
   distance temp;
   temp.inch=d1.inch+d2.inch;
   temp.feet=d1.feet+d2.feet;
   if(temp.inch>=12)
     {
     temp.inch-=12;
     temp.feet++;
     }
    return temp;
   }

 void main()
   {
   clrscr();
   distance d1,d2;
   distance ans;
   cout<<" first enter inches & then feet in both distances "<   cout<<" enter the 1st distance ";
   cin>>d1.inch;
   cin>>d1.feet;
   cout<<" enter the 2nd distance ";
   cin>>d2.inch;
   cin>>d2.feet;
   ans=add(d1,d2);
   cout<<" new distance :-"<   }

Posted Date: 10/22/2012 5:06:24 AM | Location : United States







Related Discussions:- Program to add 2 distances & show sum as new distance, Assignment Help, Ask Question on Program to add 2 distances & show sum as new distance, Get Answer, Expert's Help, Program to add 2 distances & show sum as new distance Discussions

Write discussion on Program to add 2 distances & show sum as new distance
Your posts are moderated
Related Questions
TO CONVERT A NUMBER OR A DIGIT INTO ALPHABET

What are the various types of control structures in programming? - Primarily there are 3 types of control structures in programming: Sequence, Selection and Repetition. - Se

What is conversion constructor? explain it .

A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concatenation. For a string of t

Program1: Write a program to find the factorial of a given number. The input is user given. Final output is printed out on to the screen. Program2: Write a program to gene

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

algorithm to prepare mark sheet of a student by inputing name,branchcode,semester,register no,5 marks of students and total mark of student


Differentiate between the expression "++a" and "a++"? - With ++a, increment happens first on variable a, and resulting value is used. This is known as prefix increment. - Wi

Binomial coefficients are the numeric factors of the products in a power of a binomial such as (x + y)n. For example, (x + y)2 = x2 + 2 x y + y2 has the coefficients 1 2 1. Binomia