I'm struggling with some errors when I write programs using real values (float and double types). When declaring "real" as double, in watches debugging tool the value relative to this variable isn't showed in a comprehensible way. Also, the program doesn't give me the right output and I'd like to know why.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,integer;
double real = 0;
double average = 0;
printf("enter a real value: ");
scanf("%f",&real);
for (i=0; average < real; i++){
printf("enter an integer: ");
scanf("%d",&integer);
average = float((average+integer)/(i+1));
}
printf("\n%d numbers have been added!", i);
printf("\nthe average of all entered numbers is: %.2f",average);
return 0;
}
Some variables could not correspond because I've translated it right now to make it more comprehensible for you.
I've tried using cast operators, removing them, using float and double in declaration getting no acceptable result (and program won't work either)
EDIT: program is working now, but still have some math problems, result isn't the one i was expecting https://i.stack.imgur.com/Zl9dJ.jpg