d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > For Loops > C++
12Next
Add Reply New Topic New Poll
Member
Posts: 9,916
Joined: May 11 2007
Gold: 3,280.00
Oct 18 2012 12:54am
int main(void)
{


for (double x=90.1;x<4.1;x-2)
{
cout << x;
}

return 0;
}

How can I change the increments for the for loop for something like decreasing by 2 or dividing each number by two, or adding 2 to each number.
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Oct 18 2012 04:14am
x = x [+,/,-.*] a;

where [..] are various math operations and 'a' is some number


ex:

x = x*2

I think this should work

This post was edited by Eep on Oct 18 2012 04:14am
Member
Posts: 9,916
Joined: May 11 2007
Gold: 3,280.00
Oct 18 2012 10:31am
Will be paying for help along with other problems within this homework assignment.
Member
Posts: 9,916
Joined: May 11 2007
Gold: 3,280.00
Oct 18 2012 10:43am
Nothing will print no matter what I do D:
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 18 2012 11:26am
Quote (Speed93 @ Oct 18 2012 02:54am)
int main(void)
{


for (double x=90.1;x<4.1;x-2)
{
  cout << x;
}

return 0;
}

How can I change the increments for the for loop for something like decreasing by 2 or dividing each number by two, or adding 2 to each number.


Quote (Speed93 @ Oct 18 2012 12:43pm)
Nothing will print no matter what I do D:


Read the bold very carefully.
Member
Posts: 2,429
Joined: Jul 22 2010
Gold: 104.60
Oct 18 2012 11:41am
Quote (Speed93 @ Oct 18 2012 08:54am)
int main(void)
{


for (double x=90.1;x<4.1;x-2)
{
  cout << x;
}

return 0;
}

How can I change the increments for the for loop for something like decreasing by 2 or dividing each number by two, or adding 2 to each number.


besides the logical error in the condition section, there is another error in the increment section: x-2 does nothing. x=x-2 would be nice.
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Oct 18 2012 03:34pm
Quote (stecman @ Oct 18 2012 12:41pm)
besides the logical error in the condition section, there is another error in the increment section: x-2 does nothing. x=x-2 would be nice.


I posted about that but completely ignored the logic error.....fiddles
Member
Posts: 9,916
Joined: May 11 2007
Gold: 3,280.00
Oct 19 2012 07:25pm
Quote (Eep @ Oct 18 2012 05:34pm)
I posted about that but completely ignored the logic error.....fiddles


I fixed it and submited thanks,
It was alot easier to do..... x - = 2
or x / = 2
rather than assigning the contain the expression value

Member
Posts: 6,325
Joined: Dec 2 2007
Gold: 2,347.75
Oct 26 2012 07:19pm
you can use this instead of what you have typed:

Code

for(;;){
   //no just kidding :D
}


pick up a book, if you read the first chapters those things will be covered
Member
Posts: 1,756
Joined: Feb 9 2011
Gold: 112.63
Nov 6 2012 09:14pm
-__- lol
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll