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
Printable View
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
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;
but i dont want to loop it... i just want to do it once
i've tried for hours to make it work without a for loop but whenever i do the results dont come out right...
This code is performing the operationsCode:...
for (lvl = 1; lvl <= maxlevel; outputnum = Math.floor(points / 4), lvl++) {
diff = Math.floor(lvl + 300 * Math.pow(2, lvl / 7));
points += diff;
...
}
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
this is what i tried:
and it didnt work:mad: :confused: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);
}
i tried typing in 52... and it outputted: 136,669
it should have come out as 123,660