another if else prob...

suppose that Average is a student's semester average and that final is the student's grade on the final exam. write a statement which assigns a semester average as follows: if Average and Final Are less than 10 points apart, the semester average is the average of the two; otherwise, the semester averafe is the larger of the two.

my code so far;

#include <conio.h>
#include <stdio.h>

float d,i;

main (void)
{
clrscr();
printf ("Avereage:");
scanf ("%f", & d);
printf ("Final:");
scanf ("%f", & i);


if (d<i)
printf ("Semester Average:%f",i);

else if (i<d)
printf ("Semester Average:%f",d);


getch();
return 0;
}

i have a problem making a code for the statement "if Average and Final Are less than 10 points apart, the semester average is the average of the two".. can someone pls help me.. i need it asap.. I'm kinda new to c++... thanks a lot i would appreciate all the help i can get... :)
your code is written in pure C, not C++
@topic
operators will do the job here, something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
double myFunction( double x, double y)
{
     if (x > y )
        return x;
     return y;
}

//main
//...
if( Average < 10 && Final < 10 )  // && logical AND
    SemAverage = (Average + Final) / 2;
else
    SemAverage = myFunction(Average,Final);


EDIT - sorry I haven't read your post till end
Last edited on
all i know is the basic so I'm yet not that familiar with "// && logical AND
/* do something */" and I've tried inserting the code you gave but it has no effect.. any other suggestion?? by the way thanks.. :)
if Average and Final Are less than 10 points apart


if( abs( average - final ) < 10 )

the semester average is the average of the two;


semester_average = ( average + final ) / 2;

otherwise,


else

the semester averafe is the larger of the two.


semester_average = std::max( average, final );

If you don't know about std::max, or cannot use it, then I'll let it up to you to figure it out.
Last edited on
Topic archived. No new replies allowed.