# Math formula (js -->C++)

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 04-29-2003
Demon1s
to tell you the truth, i dont have the slightess clue what a for loop is. I only know Ifs and Whiles and elifs and n00b stuff like that... could som1 plz tell me how to make it so u input the lvl number instead of it just outputting a bunch of lvls
• 04-30-2003
Magos
A for-loop repeats a piece of code a set amount of times. Read the tutorials @ http://faq.cprogramming.com/cgi-bin/smartfaq.cgi for indepth explanations.
Code:

```int Exp = 0; for(X = 1; X < L; X++) {   Exp += (X + (int)(300.0 * pow(2, ((double)X / 7.0)))); } Exp /= 4;```
• 05-01-2003
Demon1s
but i dont want to loop it... i just want to do it once
• 05-01-2003
Demon1s
i've tried for hours to make it work without a for loop but whenever i do the results dont come out right...
• 05-01-2003
confuted
Code:

```... for (lvl = 1; lvl <= maxlevel; outputnum = Math.floor(points / 4), lvl++) {         diff = Math.floor(lvl + 300 * Math.pow(2, lvl / 7));         points += diff;         ... }```
This code is performing the operations
outputnum = Math.floor(points / 4)
diff = Math.floor(lvl + 300 * Math.pow(2, lvl / 7));
points += diff;
several times: once for level 1, and once more for every level up to and including maxlevel. So, what you want to do looks something like this in C...

Code:

```float func2(float maxlevel)  //is maxlevel an int or unsigned int instead, perhaps?  you probably don't need a float { ... for (float lvl=0; lvl <= maxlevel; lvl++)  //probably don't need a float for lvl either {         diff = floor(lvl + 300 * pow(2, lvl / 7));         points += diff; } return(floor(points/4);)  //just returning the value of outputnum instead of using a variable```
• 05-02-2003
Demon1s
this is what i tried:

Code:

```#include<iostream.h> #include<conio.h> #include<math.h> float func2(float maxlevel)//is maxlevel an int or unsigned int instead, perhaps?  you probably don't need a float {     float diff,points,x;     for (float lvl=0; lvl <= maxlevel; lvl++)  //probably don't need a float for lvl either     {         diff = floor(lvl + 300 * pow(2, lvl / 7));         points += diff;         x=floor(points/4);         if(lvl == maxlevel)         {                 cout <<"\n"<< x;                 getch();         }                 //just returning the value of outputnum instead of using a variable     }         } int main()        {     int maxlevel = 1;     cout << "Enter max lvl: ";     cin >> maxlevel;     func2(maxlevel); }```