Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: increase by 20 for every 3 to 4 hours

1. ## increase by 20 for every 3 to 4 hours

Hi,

how do I write a code for something like this, increase by a value of 20 for every 3 hours,

meaning..if its 3 hours = it should be 20, and if its 6 hours, it should be 40..and so on..
I think it should be done by for loop..

2. If currentHour is a dynamic number and this method is called every hour, something along the lines of...

Code:
```currentHour
number

if(currentHour%3==0)
number+=20;```
If you have currentHour and want number to be determined...

Code:
```while(currentHour>0)
{
if(currentHour-3>0)
number+=20;
currentHour-3;
}```

3. ## Users who have thanked KULP for this post:

cally0611 (03-27-2013)

4. Hey KULP,
this is my version...with a for loop...just for beginners out there like me

#include<iostream>
using namespace std;

int main()
{
int hours, value=0;

cout<<"Enter the number of hours"<<"\n";
cin>>hours;

for(int i=1;i<=hours;i++)
{
if(i%3==0)
{
value=value+20;
cout<<value;
}
}
}

in C++

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•