Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to write the HIGHEST are of the code? A.S.A.P

Posted on 2001-06-07
4
Medium Priority
?
250 Views
Last Modified: 2010-04-02
I have a problem with my code and I need some help to figure out the code. The purpose of the code is to enter the grades and display the overall average.  Also to display the highest grade entered.  the output of the code should show the overall average of the grades entered and the highest grade entered... my biggest problem is I can't figure out the code to display the hightest grade ... Please give suggestions or please fix the code/
thank you
 
 
 
#include <stdio.h>
#define HIGHEST 90
int highest[HIGHEST];
int  main()
{
   float average;              /* new data type */
   int counter, grade, total, highest;
   /* initialization phase */
   total= 0;
   counter= 0;
   highest=80;
   /* processing phase */
   printf( "Enter grade, -1 to end: " );
   scanf( "%d", &grade );
   printf("High grade");
   scanf("%d", &highest);

   while ( grade != -1 ) {
      total = total + grade;
      counter = counter + 1;
      printf( "Enter grade, -1 to end: " );
      scanf("%d", &grade);
  }
  while(grade > highest) {
   grade=highest;
   printf("High");
   scanf("%d", &highest);
  }

   average = ( float ) total / counter;
      printf( "Class average is %.2f", average );
   return(highest);
         }
0
Comment
Question by:Nancy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 31

Accepted Solution

by:
Zoppo earned 200 total points
ID: 6167227
Hi Nancy,

You simply want to output the highest value of the entered values?

...
highest = -1; // I assume no negative grades will be entered

while ( grade != -1 )
{
 if ( grade > highest )
  highest = grade;
 ...
}
 // I don't know for what reason you wanted another loop here which of course
 // gets never called since (grade>highest) here would evaluate to (-1>80) which is never true
 average = ( float ) total / counter;
 printf( "Class average is %.2f", average );
 return(highest);
}

further you should take care about two instances of 'highest', first global as array and second
in scope of main as int...

ZOPPO
0
 
LVL 4

Expert Comment

by:IainHere
ID: 6167859
Also, don't use #define, use
const int HIGHEST = 90;
instead (unless this is a C question out of topic :) You get free type checking, and your debugger will be more helpful. Good luck with the course ;-)
0
 
LVL 11

Expert Comment

by:griessh
ID: 6811715
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days.
Unless there is objection or further activity,  I will suggest to accept "Zoppo" comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

Please do not accept this comment as an answer!
======
Werner
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6828373
Per recommendation comment force/accepted by

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question