Function parameter in C not modified after function is called -


#include<stdio.h> #include<stdlib.h> #include<conio.h> #include<time.h>  double gen(double ds) //function random double variable {     double dx=0;     dx=rand()%200+1;     ds=dx/100;     return(ds); }  int main() {     double dzahl=0;     double dtokens=1;     srand((unsigned)time(null));     double dsummand=0;     int igame=0;     for(;;)     {         printf("deine tokens:%.2lf\n", dtokens);  //this doesn't matter         printf("was m%cchtest du tun?\n[1]:generiere tokens\n[2]:spiele ein minigame\n", 148);         fflush(stdout);         scanf("%d", &igame);         fflush(stdin);         switch (igame)         {             case 1:             {                 gen(dsummand);  //function in use                 dtokens=dtokens+dsummand;                 printf("\ndu hast %.2lf tokens generiert!\n", dsummand);  //the output of value                 fflush(stdout);             }             break;         }     }      getch(); } 

the problem dsummand doesn't value ds. know problem because trying fix couldn't figure out.

i trying random double value function program. thought work unfortunately didn't.

if want value ds come out of function modified have pass pointer.

double gen(double *ds) {  *ds=dx/100; 

and

gen(&dsummand); 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -