# increase by 20 for every 3 to 4 hours

• 03-26-2013, 06:06 AM
cally0611
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..
• 03-26-2013, 06:26 AM
KULP
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; }```
• 03-27-2013, 08:51 AM
cally0611
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++