C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-20-2009, 05:14 PM   #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.
copelli39 is offline   Reply With Quote
Old 04-20-2009, 05:24 PM   #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   Reply With Quote
Old 04-20-2009, 05:26 PM   #3
+++ OK NO CARRIER
 
quzah's Avatar
 
Join Date: Oct 2001
Posts: 10,259
Quote:
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.
__________________
Hundreds of thousands of dipshits can't be wrong.


Are you up for the suck?
quzah is offline   Reply With Quote
Old 04-20-2009, 05:32 PM   #4
Registered User
 
Join Date: Apr 2009
Posts: 4
Code:
Quote:
#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
copelli39 is offline   Reply With Quote
Old 04-20-2009, 05:50 PM   #5
+++ OK NO CARRIER
 
quzah's Avatar
 
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   Reply With Quote
Old 04-20-2009, 06:04 PM   #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   Reply With Quote
Old 04-20-2009, 06:45 PM   #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   Reply With Quote
Old 04-20-2009, 07:08 PM   #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 */
I haven't run this but that should be pretty close.
Adak is online now   Reply With Quote
Old 04-20-2009, 10:32 PM   #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   Reply With Quote
Old 04-21-2009, 01:17 AM   #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   Reply With Quote
Old 04-21-2009, 09:29 AM   #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   Reply With Quote
Old 04-21-2009, 09:37 PM   #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.
Attached Images
 
Adak is online now   Reply With Quote
Reply

Tags
arrays, c programming, c++, csc help, sum values

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 11:15 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22