I have tried to make a program that allows inputs into a 1D array. I run the program and the inputs are asked for, but the program simply continues to ask for more inputs.
I'm moderately new to C so go easy.
Any help would be appreciated
Cheers
Wonkerloop

Heres the code:

#include <stdio.h>

main()
{
float price[10];
float vatprice[10];
int count;


printf("Please enter a values to be stored in the table\n");
for (count=0;count<10;count++)
{
    printf("Value: ");
    scanf("%f",&price[10]);
}
//while (count!=10);

printf("\n%d",price[10]);
/*
do
{
    printf("\nWorking...");
    vatprice[10] = price[10] * 1.175;
    countvat==countvat+1;
}
while (countvat!=10);

printf("\nThis is our pretty table with original and Vat prices \n\n %d",vatprice[10]);
*/
return(0);
}

Recommended Answers

All 3 Replies

line 14: scanf("%f",&price[10]);

You need to use the loop counter as the index into the array, such as scanf("%f",&price[count]); And your program does not contain an infinite loop, line 10 is the correct way to code it.

Also if you declare an array like

int arr[10]

The last legal index into the array is 9. Anything beyond this and your code will crash.

Till line 15 it is ok.
And i think you were trying to like something this

Line:16
count=0;

while (count!=10)
{
printf("\n%d",price[count]);
count++;
}

printf("\nThis is our pretty table with original and Vat prices \n\n");
count=0;

while(count!=10)
{
vatprice[count] = price[count] * 1.175;
printf("\n %d",vatprice[count]);
count++;
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.