Thread: arrays

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    42

    arrays

    I keep getting syntax errors.
    Code:
    #include <stdio.h>
    
    void main()
    {
    	int number[10]; /* array of 10 numbers */
    	int count = 0;  /* count through the amount of times entered */
    	long sum = 0L;  /* The total amount of the numbers entered */
    	float average = 0.0f; /* average of the total / count */
    	int i = 0;			/* count through the array */
    	char newnum;		/* check if user wants to continue */
    
    
    	do				/* do  loop to go through the user input */
    	{
    	printf("\n Enter the numbers you wish to average:\n");	/* enter the numbers display to the user */
    	scanf("%d", &number[i]);								/* read input */
    	printf("Would you like to add more numbers? y or n");	/* check if user want to enter another number */
    	scanf("%c", &newnum);				/* read input */
    
    	if("%newnum == 'Y' || newnum == 'y')
    	{
    		printf("\n Enter the numbers you wish to average:\n");	/* enter new numbers if continue is true */
    		scanf("%d", &number[i]);	/* read new numbers into array */
    	}
    	else
    	
    
    	for(i = 0; i < count; i++)			/* else display the value of the numbers entered into the array */
    	{
    		printf("%d", i+1);			/* display the number of the array plus one to diplay sequenceto user */
    		scanf("The value you entered was %d", &number[i]); /* read numbers input into the array */
    		sum += number[i];	/* sum total of numbers inthe array */
    	}
    	average = (float)sum / count;		/* average of sum of numbers divided by count of numbers */
    	
    	for(i = 0; i < count; i++)	
    	{
    	printf("\nThe Number %d was %d", i + 1, number[i]);	/* display the number of the line and the corresponding value in the array */
    	printf("\n Average of the numbers entered is : %f\n", average); /* display the average of all numbers entered in the array */
    	printf("Would you like to continue? Y/N\n"); /*check if the user would like to enter a new set of numbers into the array */
    	scanf(" %c", &newnum); /* read input */
    	}
    	}while("%newnum == 'Y' || newnum == 'y'); /* if the user wants to continue, continue */
    
    	
    
    }

    CODE TAGS added by Hammer
    Last edited by john_murphy69; 02-11-2003 at 01:49 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function to read in two arrays
    By ssmokincamaro in forum C Programming
    Replies: 7
    Last Post: 11-12-2008, 07:59 AM
  2. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  3. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  4. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM