#include <stdio.h>
#include <stdlib.h>
#include<time.h>
void averageGuess(int);
int main()
{
int i, userInput, compGuess, totalGuess, loopGuess = 0;
srand(time(NULL));
printf("Please enter a number between 0 and 99: \n");
scanf("%d", &userInput);
for(i = 0; i < 50; i++)
{
loopGuess = 0;
do
{
compGuess = (rand() % 100);
loopGuess++;
} while(compGuess != userInput);
totalGuess += loopGuess;
}
averageGuess(totalGuess);
return 0;
}//end main
void averageGuess(int totalGuess)
{
float average;
average = totalGuess / 50;
printf("The program took an average of %lf random number generations to match the target number over the 50 experiments.", average);
}//end function
The goal is for the program to print out a float but all I get is integers. I've compiled it in Codeblocks and an Online C compiler but the latter is giving me negative numbers while Codeblocks doesn't return a float.
Can't tell if it is an issue with my code or compiler.