Thread: Need a lot C programming help PLEASE!

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    4

    Unhappy Need a lot C programming help PLEASE!

    I have an assignment due Thursday morning and I cannot figure this out for the life of me. If someone could please help with this it would be very much appreciated! Here's the problem:

    1. Supply the C source code on a thumb drive, 3.5" diskette, or CD.
    2. Label the disk with:
    a. Your name(s)
    b. CSC 120
    c. Group number
    d. Your e-mail address.
    3. Name your program main.C
    4. At the top of the program, place a comment header containing:
    a. Your name(s)
    b. CSC 120
    c. Group number
    d. Your e-mail address
    e. Program 2
    5. Properly comment the program.
    6. Only turn in a program that will compile without errors. A program that has compile
    errors will not be graded.
    7. Make sure there are no errors on the thumb drive, diskette, or CD. If a program cannot be
    compiled or executed because of disk errors, the program will not be graded.
    8. Write a C program that will continuously prompt for and read integers between 0 and 100
    inclusive. The program will read these numbers and store them into an array called
    grades. The array grades will have a size of 10. The program will stop prompting for
    and reading integers when 10 integers have been read or when the last integer was less
    than 0 or greater than 100. After the last valid integer is read, the program will then sum
    all of the entered integers located in the array grades. Do not sum the numbers as they
    are read into the program. After the sum is calculated, the program will calculate the
    integer average of the grades. Finally, the program will print all of the grades, the sum,
    the count and the average of the entered grades. RUN THE SAMPLE PROGRAM TO
    SEE HOW IT SHOULD WORK.
    9. Do not use any GOTO's.

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    What have you tried first of all? Also read the forums homework policy.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1. Supply the C source code on a thumb drive, 3.5" diskette, or CD.
    I've completed the above, but for some reason, it won't let me attach a physical disk to the forum. So sadly, I cannot give you the work you ask for.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Apr 2009
    Posts
    4
    Code:
    #include <stdio.h> main() { /* Variable Declarations */ int x = 0, grades[100], maximum, minimum, average, sum, numGrades, temp; char changed = 'T'; /* Prompt user to enter the number of grades to process */ printf ("Enter the numer of grades to process (0 - 100): "); scanf ("%i", &numGrades); /* Check to make sure number of grades entered is between 0 - 100 */ while (numGrades < 0 || numGrades > 100) { printf ("*** Invalid number of grades. Please enter 0 - 100. ***\n"); printf ("Enter the numer of grades to process (0 - 100): "); scanf ("%i", &numGrades); } /* end while */ /* If user enters 0 grades to be entered, end program */ if (numGrades == 0) { return 0; } /* end if */ /* Set minimum, maximum, and sum values to default values for correct ouput */ minimum = grades[0]; maximum = grades[0]; sum = 0; /* Prompt user to enter each grade per number of grades entered using a for loop to continue through the array */ for (x = 0; x < numGrades; x++) { printf ("Enter grade for student #%i: ", x + 1); scanf ("%i", &grades[x]); /* Check to make sure each grade is between 0 - 100 */ while (grades[x] < 0 || grades[x] > 100) { printf ("*** Invalid grade entered. Please enter 0 - 100. ***\n"); printf ("Enter grade for student #%i: ", x + 1); scanf ("%i", &grades[x]); } /* end while */ /* Determine minimum grade by comparing to current minimum (default set as first grade entered) */ if (grades[x] < minimum) { minimum = grades[x]; } /* end if */ /* Determine maximum grade by comparing to current maximum (default set as first grade entered) */ if (grades[x] > maximum) { maximum = grades[x]; } /* end if */ /* Keep track of sum of grades to calculate average later */ sum = sum + grades[x]; } /* end for */ /* Calculate average of grades */ average = sum / numGrades; /* Display the minimum, maximum, and class average grades */ printf ("\nThe minimum grade is %i\n", minimum); printf ("The maximum grade is %i\n", maximum); printf ("The class average is %i\n", average); /* Start while loop to sort array in ascending order by keeping track if grades place is changed or not */ while (changed == 'T') { changed = 'F'; /* Start for loop to check if grades need to be resorted if current grade in the array is larger than the next */ for (x = 0; x < numGrades; x++) { /* If current grade is larger than the next, swap their places */ if (grades[x] > grades[x + 1]) { temp = grades[x]; grades[x] = grades[x + 1]; grades[x + 1] = temp; changed = 'T'; } /* end if */ } /* end for */ } /* end while */ /* Display the grades entered in ascending order */ printf ("The %i Grades entered were:\n", numGrades); /* Start for loop to show each grade in order */ for (x = 0; x < numGrades; x++) { printf ("%i ", grades[x]); } /* end for */ printf ("\n"); return 0; } /* end main */
    is what ive tried, but it does not do what ive inteded it to do. its supposed to take 10 numbers between 0 and 100 and i need this program to use array called "grades". and the program has to stop after 10, sum and average the grades and then the programs supposed to sum avg and count the grades

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You should only store 10 grades then, not 100 of them.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Dec 2008
    Posts
    104
    This program should take about 7 - 10 lines, and yours is taking 111.

    You are over-complicating your whole program when it should be VERY easy. Review your program.

  7. #7
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Indent and format code properly so it doesn't scroll off the sides; makes it kinda' impossible to read.

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Code:
    			
    #include <stdio.h>
    
    int main()
    {
    	/* Variable Declarations */
    	int i, x = 0, grades[10], maximum, minimum, average, sum, numGrades, temp;
    	char changed = 'T';
    	
    
    /* This block of code does not comply with the assignment - delete it*/
    	/* Prompt user to enter the number of grades to process */
    	printf ("Enter the numer of grades to process (0 - 100): ");
    	scanf ("%i", &numGrades);
    	/* Check to make sure number of grades entered is between 0 - 10 */
    	while (numGrades < 0 || numGrades > 10)
    	{
    		printf ("*** Invalid number of grades. Please enter 0 - 100. ***\n");
    		printf ("Enter the numer of grades to process (0 - 100): ");
    		scanf ("%i", &numGrades);
    	} /* end while */
    	
    	/* If user enters 0 grades to be entered, end program */
    	if (numGrades == 0)
    	{
    		return 0;
    	} /* end if */
    	
    
    
    	
    	/* Prompt user to enter each grade using a for loop to continue through the array */
    	for (x = 0; x < 10; x++)
    	{
    		printf ("Enter grade for student #%i: ", x + 1);
    		scanf ("%i", &temp);
    		
    		/* Check to make sure each grade is between 0 - 100 */
    		if (temp < 0 || temp > 100)
                   {
    		   printf ("*** All Grades Have Been Entered ***\n");
                       break;
                    }
                    else
                      grades[x] = temp;
    
    	} /*end for*/	
    
    
             /* Begin Processing Data */
    
            /* Set minimum, maximum, and sum values to default values for correct ouput */
    	minimum = grades[0];
    	maximum = grades[0];
    	sum = 0;
    
    
            for(i = 0; i < x; i++)  {
    		/* Determine minimum & maximum grade by comparing to current 
    		minimum defaults (default set as first grade entered) */
    		if (grades[i] < minimum)
    		   minimum = grades[i];
    
    		if (grades[i] > maximum)
    			maximum = grades[i];
    		
    		/* Keep track of sum of grades to calculate average later */
    		sum = sum + grades[i];
    	} /* end for */
    	
    
    	/* Calculate average of grades */
            numGrades = x - 1;
    	average = sum / numGrades;;
    	
    	/* Display the minimum, maximum, and class average grades */
    	printf ("\nThe minimum grade is %i\n", minimum);
    	printf ("The maximum grade is %i\n", maximum);
    	printf ("The class average is %i\n", average);
    	
    	/* Start while loop to sort array in ascending order
    	by keeping track if grades place is changed or not */
            changed = 'T';
    	while (changed == 'T')
    	{
    		changed = 'F';
    		
    		/* Start for loop to check if grades need to be resorted
    	 	if current grade in the array is larger than the next */
    		for (x = 0; x < numGrades - 1; x++)
    		{
    			/* If current grade is larger than the next, swap their places */
    			if (grades[x] > grades[x + 1])
    			{
    				temp = grades[x];
    				grades[x] = grades[x + 1];
    				grades[x + 1] = temp;
    				
    				changed = 'T';
    			} /* end if */
    		} /* end for */
    	} /* end while */
    	
    	/* Display the grades entered in ascending order */
    	printf ("The %i Grades entered were:\n", numGrades);
    	
    	/* Start for loop to show each grade in order */
    	for (x = 0; x < numGrades; x++)
    	{
    		printf ("%i ", grades[x]);
    	} /* end for */
    	
    	printf ("\n");
    	
    	return 0;
    
    } /* end main */
    I haven't run this but that should be pretty close.

  9. #9
    Registered User
    Join Date
    Apr 2009
    Posts
    4
    thanks a lot for all of the help! ive been getting the same product as the program above^^ but somehow im supposed to get this as my answer...

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Sorry, I won't be d/l'ing and running any executable programs from people I don't know.

    If you can't explain what you need, or show a screenshot of it, then you're out of luck.

  11. #11
    Registered User
    Join Date
    Apr 2009
    Posts
    4
    How would I put a screen shot up? i have the file saved i just dont know how im supposed to post it

  12. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Click on Post Reply button, then look at the bottom part of the reply page, you'll see a button for "manage attachments".

    Click on it

    Then click on "browse", and select your image file. If it's too big for the forum (doubtful), you'll have to edit it.

    Then click on "upload".

    You can also do it another way - post the pic up to a pic depot like photobucket.com, and then paste the url to that photo, in the url line in the upload page.

    Either way.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting a file with a lot of words.
    By samus250 in forum C Programming
    Replies: 28
    Last Post: 04-27-2008, 01:36 PM
  2. C(xx), Brag and Flame a lot!
    By xuftugulus in forum A Brief History of Cprogramming.com
    Replies: 62
    Last Post: 03-20-2008, 11:15 PM
  3. A lot can happen in 50 years
    By Salem in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 10-04-2007, 04:44 AM
  4. using fopen getting a lot of warnings
    By netiad in forum C Programming
    Replies: 1
    Last Post: 04-28-2007, 08:44 PM
  5. Still get error even if i changed a lot..
    By icefire99 in forum C++ Programming
    Replies: 9
    Last Post: 04-26-2007, 03:31 AM

Tags for this Thread