[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

hey I know its not my personal request website but I have to

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 12
Thread images: 1

File: integral.png (28KB, 875x504px) Image search: [Google]
integral.png
28KB, 875x504px
hey I know its not my personal request website but I have to hand it in tomorrow and I dont know wtf is wrong, its probably a shitty mistake any tips?
>>
it's for a calculus II project and I dont want to repeat this course, my grade relies for 15% on this please help
>>
integral must return a value is my error
if it helps;
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>

int count;
float total, inBox;
// user defined function below
float f(float x) {
return exp(cos(x));
}
//function to calculate a definite integral given bounds of integration (xmin/max) & bounds of function (ymin/ymax)
float integral(float(*f)(float), float xmin, float xmax, float ymin, float ymax) {
for (count = 0; count < 1000000; count++) {
float u1 = (float)rand() / (float)RAND_MAX;
float u2 = (float)rand() / (float)RAND_MAX;

float xcoord = ((xmax - xmin)*u1) + xmin;
float ycoord = ((ymax - ymin)*u2) + ymin;
float val = f(xcoord);

total++;

if (val > ycoord) {
inBox++;}
}
float density = inBox / total;
std::cout << (xmax - xmin)*(ymax - ymin)*density << std::endl;
}
int main() {
std::cout << "RESULT: " << std::endl;
integral(f, -2, 2, 0, 4);
}
>>
>>61205773
1. Retard. Use
 tags not screen shots.
2. Retard. We're not here to do your homework for you. Fuck off, poojeet.
3. Use C++11 or kill yourself you absolute fucking imbecile.
>>
>>61205803
a poojeet would have solved this by now mate you kw that,Im already in the shitter as of takin calculus in the summer semester
>>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>

int count;
float total, inBox;
// user defined function below
float f(float x) {
return exp(cos(x));
}
//function to calculate a definite integral given bounds of integration (xmin/max) & bounds of function (ymin/ymax)
float integral(float(*f)(float), float xmin, float xmax, float ymin, float ymax) {
for (count = 0; count < 1000000; count++) {
float u1 = (float)rand() / (float)RAND_MAX;
float u2 = (float)rand() / (float)RAND_MAX;

float xcoord = ((xmax - xmin)*u1) + xmin;
float ycoord = ((ymax - ymin)*u2) + ymin;
float val = f(xcoord);

total++;

if (val > ycoord) {
inBox++;}
}
float density = inBox / total;
return (xmax - xmin)*(ymax - ymin)*density;
}
int main() {
std::cout << "RESULT: " << integral(f, -2, 2, 0, 4) << std::endl;
}
>>
>>61205819
what was the mistake? could you explain?
May God bless you kind sir xD
>>
>C style casts

kys
y
s
>>
>>61205732

I didn't post the solution, but you're not returning a value in integral().
>>
>>61205834
You defined that function integral should return float value, but you actually never returned any value..
>>
>>61205732
>global variables
I'd fail you from the course just for that alone.

>passing a function pointer instead of just using a std lambda
>not using auto
>c-style casting instead of static_cast
>cout inside a math function
Don't help him. We don't want or need any more poojeets or dumb fucks shitting up the profession.
>>
>>61205732
>too stupid to read the compiler errors
Thread posts: 12
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.