Today, we are going to discuss a simple program logic that uses only input, output and assignment statements along with variable declarations.

Points of Discussion are:

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int h, w, d, hrs;

cout<<"Enter Hours=";

cin>>hrs;

h = hrs;

w = hrs / 168;

hrs = hrs % 168;

d = hrs / 24;

hrs = hrs % 24;

cout<<"Total Hours input = "<<h<<endl;

cout<<"Weeks ="<<w<<endl;

cout<<"Days ="<<d<<endl;

cout<<"Hours ="<<hrs;

getch();

}

Enter Hours= 200

Total Hours input =200

Weeks = 1

Days =1

Hours =8

We know that:

1 day = 24 hours

so 1 week = 24 x 7 = 168 hours

Therefore we will divide total hours by 168 to get weeks.

weeks = 200 / 168 will give 1 week.

Now to calculate remaining hours we will get remainder of the division 200 % 168

This will give remaining hours = 32

To get days, we will divide remaining hours by 24

so 32 / 24 will give 1 day.

Now we will calculate remaining hours by remainder 32 % 24 that will give the result 8 hours.

So the output 1 week, 1 day and 8 hours.

If you enjoyed the C++ Learning Through Example program Logic Understanding, Please share this blog on Social media. Thanks!

Points of Discussion are:

- C++ Program: Input Hours Convert into Weeks, Days and Hours.
- Algorithm of the Hours Conversion Program
- C++ Code of the Hours Conversion Program.
- Understanding Logic of The Hours into Week, Day and Hours Program

## ALGORITHM : Hours Conversion

- Start
- Input Hours
- Calculate Weeks = Hours / 168
- Calculate Hours = Hours Mod 168
- Calculate Days = Hours / 24
- Calculate Hours = Hours Mod 24
- Display "Weeks=", Weeks
- Display "Days=", Days
- Display "Hours =", Hours
- End

## C++ Code: Program Hours Conversion into Weeks, Days and Hours.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int h, w, d, hrs;

cout<<"Enter Hours=";

cin>>hrs;

h = hrs;

w = hrs / 168;

hrs = hrs % 168;

d = hrs / 24;

hrs = hrs % 24;

cout<<"Total Hours input = "<<h<<endl;

cout<<"Weeks ="<<w<<endl;

cout<<"Days ="<<d<<endl;

cout<<"Hours ="<<hrs;

getch();

}

## OUTPUT of Sample Run of The Program Hours Conversion

Enter Hours= 200

Total Hours input =200

Weeks = 1

Days =1

Hours =8

## Logic of The Program Hours Conversion

We know that:

1 day = 24 hours

so 1 week = 24 x 7 = 168 hours

Therefore we will divide total hours by 168 to get weeks.

weeks = 200 / 168 will give 1 week.

Now to calculate remaining hours we will get remainder of the division 200 % 168

This will give remaining hours = 32

To get days, we will divide remaining hours by 24

so 32 / 24 will give 1 day.

Now we will calculate remaining hours by remainder 32 % 24 that will give the result 8 hours.

So the output 1 week, 1 day and 8 hours.

If you enjoyed the C++ Learning Through Example program Logic Understanding, Please share this blog on Social media. Thanks!