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

This is a discussion on Math formula (js -->C++) within the C++ Programming forums, part of the General Programming Boards category; to tell you the truth, i dont have the slightess clue what a for loop is. I only know Ifs ...

1. 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

2. 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;```

3. but i dont want to loop it... i just want to do it once

4. i've tried for hours to make it work without a for loop but whenever i do the results dont come out right...

5. 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```

6. 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);
}```
and it didnt work
i tried typing in 52... and it outputted: 136,669
it should have come out as 123,660

Page 2 of 2 First 12