Re: Programming project help



On Tue, 4 Nov 2008 18:39:10 -0800 (PST), "\"The Master\""
<jordanvdf@xxxxxxxxx> wrote:

Hey, I am working on a project where a program has to read in a
collection of exam scores ranging in value from 0 ? 100. The program
should count and print the number of outstanding scores (90-100) the
number of satisfactory scores (60-89) the number of unsatisfactory
scores (0-59) and the number of invalid scores (less than 0 or greater
than 100).

The program should print output starting at the top of the page with
your name followed by some column headings to identify the output.
example:
Outstanding Satisfactory Unsatisfactory Invalid
90 89
44 212
98 76
35 -8

This is what I have for my source code so far. But I am having
problems getting the data to display correctly.

#include <stdio.h>

int main(void)
{

// Programmer Jordan Van der Flier
// November 2008

// Categorizes a list of grades, calculates, max, min, and avg


FILE *in; // delcares a file type, assigns name 'in'

Do you really think this type of comment is in any way helpful.


int grade;
int max, min, avg;
int count = 0;
int outstanding, satisfactory, unsatisfactory, invalid;

// associates 'in' with file location
in = fopen("i:\\numbers.dat", "r"); // file
location,
"r" means read

This is why you should not use // comments for code you intend to post
to a newsgroup. Anyone who might have been tempted to compile your
code will be turned off by the large number of manual edits required.

You should always check that fopen succeeds before attempting to use
the FILE* it returns.


fscanf(in, "%d", &grade); // scans from
external source

You should also check that fscanf succeeds. It returns a value to let
you do just that.


printf(" Outstanding Satisfactory Unsatisfactory
Invalid ");
printf("\n Grade Grade
Grade Grade");

while(! feof(in)){ // while 'not' at
End Of File

if(90 <= grade && grade <= 100){ // grades
90-100
outstanding = grade;

Your problem statement said to print the count of grades, not the
grades themselves.

printf("\n %d", outstanding);
}

else if(60 <= grade && grade <= 89){ // grades
60-89
satisfactory = grade;
printf(" %d", satisfactory);

You omitted the \n in this and the following printf calls.

}

else if(0 <= grade && grade <= 59){ // grades
0-59
unsatisfactory = grade;
printf(" %d", unsatisfactory);

}

else if(0 > grade || grade > 100){ // grades
less than 0 or
greater than 100
invalid = grade;
printf(" %d", invalid);
}

else {}

Is there any possibility that this else can be reached?


fscanf(in, "%d", &grade);
}
fclose(in);

return(0);

You are missing a } to mark the end of main.

--
Remove del for email
.



Relevant Pages

  • Programming project help
    ... number of satisfactory scores the number of unsatisfactory ... scores and the number of invalid scores (less than 0 or greater ... int main ... outstanding = grade; ...
    (comp.lang.c)
  • programming project, revise
    ... number of satisfactory scores the number of unsatisfactory ... int main ... int outstanding, satisfactory, unsatisfactory, invalid; ... outstanding = grade; ...
    (comp.lang.c)
  • Using arrays in C.
    ... the grade. ... int enterInfo ... cin>> Stud_Num; ... cin>> response1; ...
    (comp.lang.c)
  • Re: An array within a table--Break into 1-to-1 mini tables or separate rows?
    ... multiple rows for keeping the grade values. ... User interface should not drive table structures. ... The reason I kept leaning towards putting the six grade fields into 1 ... Grade_CommunicationRating Int ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Sony rethinks flat screen focus
    ... Grade 1 would be wasted at home and the case wouldn't look ... Professional monitoring equipment is intended to tell the truth about the signal, even if looks bad, whereas domestic displays will sell better if they can make a bad signal look good. ... Perhaps it's better to marvel at domestic kit, that just needs a mere hint of sync pulses to start displaying a recognisable image through all the noise. ... Please replace invalid and invalid with gmx and net to reply. ...
    (uk.tech.digital-tv)