How to get Program recognise user input

I need the program to do a calculation after the user inputs 10 numbers
This is what I have tried so far Any ideas where I am going wrong:
int count;
float value, high,low, sum,average;
sum=0;
count=0;




input:
printf("Enter a number (enter negative value to finish program):\n");
scanf_s("%f",&value);


if(value<0) goto output;
{
count=count+1;
}
if (count==1)
{
high=low=value;
}
else
if (value>high)
{
high=value;
}
else
if(value<low)
{
low=value;
}
sum=sum+value;

goto input;


output:
average=sum/count;
if(count==10)
{
printf("total values :%d\n",count);
printf("The Highest value :%f\nLowest Value: %f\n",high,low);
printf("The average of the values is:%f\n",average);
}

Any ideas where I am going wrong


You have gone wrong in using goto. A while loop will be fine for this operation.
1
2
3
4
5
int i = 0; 
while(i < 10)
{
//Have user input numbers. 
}
I have include int i=0; and the start of the while loop but I don't understand within the while loop the coding for when the user input numbers.
Sorry but I am new to C++ programming
any other ideas
Please put code in code tags in future...

1
2
3
4
5
6
7
int i = 0; 
while(i < 10) //Loop will run 10 times. 
{
     scanf(%f, &value); //Get value from user
     //Do your checks for low, high etc... 
     ++i; //Increment i 
}


And then after this you put your code:
1
2
3
printf("total values :%d\n",count);
printf("The Highest value :%f\nLowest Value: %f\n",high,low);
printf("The average of the values is:%f\n",average);


Why have you put this in?
1
2
3
4
if (count==1)
{
     high=low=value;
}


Sorry but I am new to C++ programming


You are doing C here...
Last edited on
Topic archived. No new replies allowed.