Accumulator Troubles: NEWBIE

This is a discussion on Accumulator Troubles: NEWBIE within the C++ Programming forums, part of the General Programming Boards category; NEWBIE TO C++ Desperately need help figuring out how to accumulate total number of grades(A, B, C Etc..) in a ...

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    2

    Angry Accumulator Troubles: NEWBIE

    NEWBIE TO C++

    Desperately need help figuring out how to accumulate total number of grades(A, B, C Etc..) in a student test program.
    I'm using an array called int avg[20] Any ideas on how to get this thing going would be great! Here's were I am... I'm not sure if I'm on the right track.
    Code:
    void totalGrades(string stuName[], int t1[], int t2[], int t3[], int avg[], short size)
    {
    
    	int x        = 0;    
    	int minScore = avg[0];    
    	int maxScore = avg[20];	 
    	int count    = 0;	  
    	int nsub = 0;
    	char grade = ' ';
    
    		x = 0;
    		while (x < 20)
    		{
    			if (avg[x] >= 90)
    				avg[x] = 'A';
    				count = count + 1;
    			if (avg[x] = >= 80)
    				avg[x] = 'B';
    			
    				x = x + 1;
    								
    		
    		} //end while
    		cout << "Total Grades: "<< count << endl;
    	
    }
    Thanks,
    Seven
    Last edited by sevenhallz; 12-08-2003 at 01:20 AM.

  2. #2
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    In the line:
    Code:
    if (avg[x] = >= 80)
    the first = will give you trouble, change that line to
    Code:
    if (avg[x] >= 80)
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    53
    you would need a { and } for your "if"īs so it would be


    Code:
    if (avg[x] >= 90)
     {
       avg[x] = 'A';
       count = count + 1;
    }
    Its all a matter of willpower

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    You could also convert all grades to 1-5, it would make stuff easier. That's the Austrian way btw.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    WDT
    WDT is offline
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    Posts
    271
    You may want your program to exit when after the suitable case is met instead of going through all of them each time in the loop, so try using switch/case statement or nested if/elses' (recommend the former). Also do what the previous two guys advise, especially oluf, if you want to execute multiple statements after a case is met.
    Last edited by WDT; 12-08-2003 at 08:18 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getting to grips with allegro and ms vc++ (newbie)
    By jimjamjahaa in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2005, 07:49 PM
  2. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 12:53 PM
  3. Newbie Programmer
    By Extropian in forum C++ Programming
    Replies: 3
    Last Post: 05-18-2004, 02:17 PM
  4. Some help for a newbie?
    By Ilmater in forum C++ Programming
    Replies: 23
    Last Post: 04-19-2004, 08:44 PM
  5. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 03:02 PM

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