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..
Printable View
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..
If currentHour is a dynamic number and this method is called every hour, something along the lines of...
If you have currentHour and want number to be determined...Code:currentHour
number
if(currentHour%3==0)
number+=20;
Code:while(currentHour>0)
{
if(currentHour-3>0)
number+=20;
currentHour-3;
}
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++