Tuesday, 29 January 2013

Write a Program to Get Age in Days in C++

c programmingThis program is for beginner student but sometime most of the professional student also want to learn these basic coding to apply in their project. In this program when you want to run it. The program will require “Enter Your Age in Year” this mean that enter you age from birth to now (eg: I am 22 Year Old, put you age in 22). 

Now in the second step it will Month and show you “Enter Your Age in Month. I will describe you in detail mean I am putting this article on June so June is come in the month of 6 so I will write 6(month).

After put all data, the program will calculate “Your Age in Days”. From Birth to Now.

Question:
Write a piece of code which enables you to enter your age in years and months and then converts it into days.

Source Code:
#include <iostream>
using namespace std;
void main ()
{         
            int age, year, month, day;
            cout<<"Enter Your Age in Year ";
            cin>>year;
            cout<<"Enter Your Age in Month ";
            cin>>month;
            age=(year*365)+(month*30);
            cout<<"Your Age in Days is "<<age;
}

Output:





Subscribe to get the latest right to your inbox:

0 comments:

Post a Comment

Some HTML Code