![]() |
| | #1 |
| Registered User Join Date: Apr 2009
Posts: 4
| 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. |
| copelli39 is offline | |
| | #2 |
| Registered User Join Date: Oct 2008 Location: TX
Posts: 1,262
| What have you tried first of all? Also read the forums homework policy. |
| itCbitC is online now | |
| | #3 | |
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,259
| Quote:
Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? | |
| quzah is offline | |
| | #4 | |
| Registered User Join Date: Apr 2009
Posts: 4
| Code:
| |
| copelli39 is offline | |
| | #5 |
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,259
| You should only store 10 grades then, not 100 of them. Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? |
| quzah is offline | |
| | #6 |
| Registered User Join Date: Dec 2008
Posts: 99
| 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. |
| abraham2119 is offline | |
| | #7 |
| Registered User Join Date: Oct 2008 Location: TX
Posts: 1,262
| Indent and format code properly so it doesn't scroll off the sides; makes it kinda' impossible to read. |
| itCbitC is online now | |
| | #8 |
| Registered User Join Date: Sep 2006
Posts: 2,504
| 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 */
|
| Adak is online now | |
| | #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... |
| copelli39 is offline | |
| | #10 |
| Registered User Join Date: Sep 2006
Posts: 2,504
| 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. |
| Adak is online now | |
| | #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 |
| copelli39 is offline | |
| | #12 |
| Registered User Join Date: Sep 2006
Posts: 2,504
| 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. |
| Adak is online now | |
![]() |
| Tags |
| arrays, c programming, c++, csc help, sum values |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sorting a file with a lot of words. | samus250 | C Programming | 28 | 04-27-2008 01:36 PM |
| C(xx), Brag and Flame a lot! | xuftugulus | General Discussions | 62 | 03-20-2008 11:15 PM |
| A lot can happen in 50 years | Salem | General Discussions | 5 | 10-04-2007 04:44 AM |
| using fopen getting a lot of warnings | netiad | C Programming | 1 | 04-28-2007 08:44 PM |
| Still get error even if i changed a lot.. | icefire99 | C++ Programming | 9 | 04-26-2007 03:31 AM |