GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-Mar-2009, 00:58
beretta beretta is offline
New Member
 
Join Date: Mar 2009
Posts: 4
beretta is an unknown quantity at this point

Help with loops?


Based on the solution of assignment #2, using exactly the same computation to determine the grade, write a program to compute the grade for a class of students. To indicate that there is no more scores; use a negative # as the first assignment score.
If assign. #1 score is negative; your program should terminate without the need to read in the rest of the scores. However, for this assignment, it is acceptable to still require input for other assignment scores if assignment #1 score is part of ONE input statement for all scores of a student.

In addition to compute and report the grade of each individual student, output a summary report showing the total number of students, and the number of students receiving each letter grade.

No credits will be given if the program contains any
compile-time or run-time error.
Remember to comment your program, uses meaningful variable names,
Have good indentation, echo-print your input, etc.

Grading scheme:
If the first assignment score for a student is O.K., then
Normal computation if all other scores are within range
If any other scores are not good, then do not count that student (ignore the rest of the score). It is also acceptable if the program repeats asking until all good scores are obtained, in that case, you have normal computation.

Maximum point Deductions for programs that can execute, and give correct answers:
1. require to input the total number of students to control the loop 10
2. keep asking whether there are more students to control the loop 2
3. A sequence of if ‘s (not using else if’s) 5
4. does not check score between 0 and 100 10
Minimal acceptable program: if any input score out of range, output an error statement and ignore the student.
Better solutions are also acceptable.
5. Minor mistakes in getting the Wrong answers for grades (A,B,C, etc.) 10
6. Minor mistakes in getting the Wrong counts for grades (A,B,C, etc.) 10
7. comments, indentation, prompts, etc. 20


that is my assignment and here is my finished assignment #2.
CPP / C++ / C Code:
int main()
{
  int asgn1, asgn2, asgn3, asgn4, test1, test2, exam, a1good, a2good, a3good, a4good, t1good, t2good, egood, asum, tsum, esum, fasgn;
  float weight1, weight2, weight3, allscore, score, i, fsum, n;
  char grade;
   
     
  //asks to enter in all the grades of the student (meaning input)

  
  
  printf("Please enter four assignment grades, two test grades, and one exam grade for each student:\n"); 
  printf("Enter first assignment grade: ");
  scanf("%d", &asgn1);
  printf("Enter second assignment grade: ");
  scanf("%d", &asgn2);
  printf("Enter third assignment grade: ");
  scanf("%d", &asgn3);
  printf("Enter fourth assignment grade: ");
  scanf("%d", &asgn4);
  printf("Enter first test grade: ");
  scanf("%d", &test1);
  printf("Enter second test grade: ");
  scanf("%d", &test2);
  printf("Enter exam grade: ");
  scanf("%d", &exam);
  //now to make sure grades are within the appropriate range will will declare parameters from 0 to 100.
  a1good=asgn1>=0&&asgn1<=100;
  a2good=asgn2>=0&&asgn2<=100;
  a3good=asgn3>=0&&asgn3<=100;
  a4good=asgn4>=0&&asgn4<=100;
  t1good=test1>=0&&test1<=100;
  t2good=test2>=0&&test2<=100;
  egood=exam>=0&&exam<=100;
  allscore=a1good, a2good, a3good, a4good, t1good, t2good, egood;
    if(allscore)
    {
       printf("all scores are good for calculation\n");
    }
    else 
    {
       printf("one or more scores are bad, please re-enter the scores\n");
       system("pause");
       return 0;
    }
  //now we must calculate the needed scores and percentages
  asum = asgn1 + asgn2 + asgn3 + asgn4; // assignment sum
  weight1 = (asum/4)*.2; // assignment weighed at 20%
  printf("Your weighted assignment grade is=%f\n", weight1);
  tsum = test1 + test2; // test sum
  weight2 = (tsum/2)*.3; // test weighed at 30%
  printf("Your weighted test grade is=%f\n", weight2);
  weight3 = exam*.5; // exam weighed at 50%
  printf("Your weighted exam grade is=%f\n", weight3);
  score = weight1 + weight2 + weight3;
    if(score<=100 && score>=85) // if statements will 
    {
      grade = 'A';
    }
    else if(score>=74)
    {
      grade = 'B';
    }
    else if(score>=63)
    {
      grade = 'C';
    }
    else if(score>=52)
    {
      grade = 'D';
    }
    else if(score<52)
    {
      grade = 'F';
    }
    else if(score<0)
    {
      grade = 'N';
    }
  printf("grade=%c\n", grade);
  system("pause");
  return 0;
}
shit is a bit sloppy, but im totally confused on what to do.
anyone care to help out?

basically this is my assignment 3 but I am confused as what to do.
  #2  
Old 10-Mar-2009, 22:27
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 932
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Help with loops?


Quote:
shit is a bit sloppy
Yes it is , , , and thanks for sharing , , , but that's not important right now...

The is a C programming forum. That phrase uses improper syntax.
And why would you want to come up in her talking like that anyhow.
Do you see others talking that way? I don't think so...

But at least you wrote something so I will offer these for your amusement:
The problem is you're using:
CPP / C++ / C Code:
/* system("pause");  
use: */
getchar(); /* instead.    Why???  because , it's the C way and NOT the M$ way.*/ 
Also:
- you should qualify each input value one at a time as it is given . . if it is wrong re-get it,
. . not as one batch at the end of 6 input values, how are you going to re-get if invalid?

This:
CPP / C++ / C Code:
allscore=a1good, a2good, a3good, a4good, t1good, t2good, egood;
has no hope of accomplishing anything useful.
I get 5 of these: warning: left-hand operand of comma expression has no effect.

maybe use some + signs? but you don't want mass-qualify anyhow so forget it ...

- I think you would be better off using a 2 dimensional array to store all the grades in.
Maybe something like:
CPP / C++ / C Code:
 int class_grades[max_nstudents][ngrades];
Then you loop through it to do input etc.

See what you think.
  #3  
Old 15-Mar-2009, 10:25
beretta beretta is offline
New Member
 
Join Date: Mar 2009
Posts: 4
beretta is an unknown quantity at this point

Re: Help with loops?


sorry for the language, and no I think you made it too complex
  #4  
Old 15-Mar-2009, 14:36
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 932
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Help with loops?


Too confusing? sorry
I made following to point out some things you might want to learn about for your programming.
CPP / C++ / C Code:
#include <stdio.h>

int main(void)
{
  #define NGRADES 3
  int a1good, a2good, a3good, allgood, good, i;
  int asgn[NGRADES];
  double gradetot= 0;

  /** point 1 **/
  a1good= 0;
  a2good= a3good = 1;
  allgood= a1good, a2good, a3good;
  printf("\nallgood= %d \n\
  So you can see, allgood only gets value of first item\n", allgood );

  /** point 2 use arrays and loops for input **/
  printf("\nInstead of trying to manage asgn1, asgn2, asgn3, use an array \n");
  for(i= 0; i < NGRADES; i++ )
  {
    good = 0;
    while(!good)
    {
      printf("  Enter assignment grade %d: ", i);
      scanf("%d", &asgn[i]);

      /* qualify the input here if it's out of arange get it again  */
      if( asgn[i] < 0 || asgn[i] > 100)
      {
        printf("Input out of range, try again. \n");
      }
      else
      {
        good++;
      }
    }
  }

  /** point 2.1  use arrays and loops for analysis and output **/
  printf("\nThe scores you entered were: ");
  for( i= 0; i < NGRADES; i++)
  {
    printf(" %d", asgn[i] );
    gradetot += asgn[i] ;      /* do other things like add the grades up */
  }
  printf(".  The grade average is: total:%d / %d = %.2f \n",
                         (int)gradetot, NGRADES, (gradetot / NGRADES) );

  /** point 3 don't use system("pause"); it is the mark of the beast **/
  printf("\nsystem(\"pause\"); <-- only works for microsoft not linux \n");
  printf("Use a standard C blocking function like getchar(); instead like this <hit enter>\n");

  /** BUT WAIT, since you used scanf above we need a 
      point 3.1  scanf() will always leave at least '\n' in stdin 
      so before you try to use getchar we need to read out all   **/

  { int c;  while( (c= getchar()) != '\n' && c != EOF );  }

  /* note that the braces create a new 'scope' in which we can declare c */
  /* now we can use getchar(); */
  printf("OK , now <hit enter>: ");
  getchar();

  return 0;
}
Try running it and adjusting things. . . The main point is: learn to use arrays.
If you can understand the array use above, move to a 2 dimensional array.
  #5  
Old 15-Mar-2009, 16:16
beretta beretta is offline
New Member
 
Join Date: Mar 2009
Posts: 4
beretta is an unknown quantity at this point

Re: Help with loops?


this assignment was to be made without arrays
  #6  
Old 15-Mar-2009, 18:31
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 932
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Help with loops?


Nevermind , go ahead and turn it in the way you have it...
  #7  
Old 15-Mar-2009, 21:25
beretta beretta is offline
New Member
 
Join Date: Mar 2009
Posts: 4
beretta is an unknown quantity at this point

Re: Help with loops?


i already finished it.
 
 

Recent GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
combine 2 struc loops into 1 loop roy918 C++ Forum 4 01-Mar-2007 08:28
Having Problems with Loops cristale10 C++ Forum 2 02-Oct-2006 14:58
nested for loops sandeepeecs C Programming Language 3 20-Aug-2006 08:49
Help with nested for loops...please. sorry newbie keperry C++ Forum 14 16-Oct-2004 11:25
Help using nested for loops dontcare C++ Forum 1 03-Oct-2004 12:33

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:54.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.