Today, we will discuss the logic of a simple C++ Program to input age in Years and Convert into Days. This is a simple C++ logic program. Simply we will multiply the years entered by user by 365 to convert years into days.
a) Program Requirements: Input your age in years, convert it into days and show the result.
Let's write down an algorithm firstb) Algorithm: Convert-Years-To-Days
- Start
- Input Your age in years
- Calculate days = years X 365
- Output "Your age in days=" , days
- Stop
c). Flow Chart: Convert Years Into Days
d.) Picture of C++ Program Years to days conversion from Turbo C++ 3.0 IDE
e). Program coding.
#include <conio.h>
void main()
{
// Declare two integer variables(for whole numbers)
int years, days;
// clear output screan and display message to user for input
clrscr();
cout<<"\n Enter Your Age in Years=";
// get input from user
cin>>years;
//calculate days
days = years * 365;
//display output message to user showing age in days
cout<<"\n Your age in days="<<days;
// make output screen stay as long as a character key is pressed
getch();
}
f).Program sample run output:
C++ Program Convert your Age from Years to days conversion
Enter Your Age in Years=17
Your age in days=6205
0 comments:
Post a Comment
We Love To Hear From You!