c - Void function error (value computed is not used) -


hi have tried couple variations of code , can't figure out how resolve these warnings.

  • the objective create modular representation of monty hall problem in c

problem

  • my outputfinalresult function fails give me correct output

error messages

 -  gcc -wall monteball.c  monteball.c: in function ‘determineoutcomestay’:  monteball.c:125:7: warning: value computed not used [-wunused-value]  monteball.c:127:3: warning: value computed not used [-wunused-value]  monteball.c: in function ‘determineoutcomeswitch’:  monteball.c:134:7: warning: value computed not used [-wunused-value]  monteball.c:136:3: warning: value computed not used [-wunused-value]  monteball.c: in function ‘getfinalchoice’:  monteball.c:119:1: warning: control reaches end of non-void function [-wreturn-type] 

an aside should worried warning?

code

void outputfinalresult (int winstay, int winswitch, int staycount, int switchcount); //function 4 print statements using arguments calculated determineoutcome functions int main (int argc, char * argv []) {   srand(time(null));   int counter = 10000;   int = 0;   int winstay;   int winswitch = 0;   int staycount;   int switchcount = 0;   int firstchoice;   int grandprize;   int revealeddoor;   int finalchoice;    (i = 0; < counter; i++)   {     firstchoice = getuserchoice ();      grandprize = determineprizelocation ();      revealeddoor = revealdoor (firstchoice, grandprize);      finalchoice = getfinalchoice (firstchoice, grandprize, revealeddoor);      if(finalchoice == firstchoice)     {       determineoutcomestay(finalchoice, grandprize, &winstay, &staycount);     } else     {       determineoutcomeswitch(finalchoice, grandprize, &winswitch, &switchcount);     }    }    outputfinalresult (winstay, winswitch, staycount, switchcount);   return 0; } int getfinalchoice (int firstchoice, int grandprize, int revealeddoor) {   int finalchoice;   int switchprobability = rand () % 2 + 1; // 50% chance of keeping or switching choice                                                                                                if (switchprobability == 1) // represents user keeping choice                                                                                                                 {     return firstchoice;   }    else if (switchprobability == 2) // represents user switching choice                                                                                                          {     finalchoice = rand () % 3 + 1; // randomizes finalchoice btw 1-3                                                                                                                   while (finalchoice == revealeddoor || finalchoice == firstchoice) // ensures finalchoice isn't door eliminated or                                               {                                                                 // door selected                                                                         finalchoice = rand () % 3 + 1;     }      return finalchoice;   } }  void determineoutcomestay(int choice, int grandprize, int * winstay, int * staycount) {   if(choice == grandprize)   {     *winstay++;   }  *staycount++; }  void determineoutcomeswitch(int choice, int grandprize, int * winswitch, int * switchcount) {   if(choice == grandprize)   {     *winswitch++;   }   *switchcount++; } 

sorry long post trying give info need receive answer. please message me if additional info needed. thanks.

most warnings want fix, they're pretty @ finding bad behaviour. in particular case:

the line

*staycount++; 

doesn't think. operator precedence says in case ++ comes first. ergo means this:

*(staycount++); 

thus warning, staycount changed not used. put parenthesis around expression might ambiguous, 1 of times

(*staycount)++; 

in getfinalchoice error self explanitory, "control reaches end of non-void function". in other words, there's path through function doesn't result in return getting called. i'll let find ;)


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -