![]() |
|
|
|||||||
![]() |
![]() |
![]() |
![]() |
Mark Forums Read |
| Programming :: Programming related discussions :: |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|
i'm still a newbie in this kind of business.. i want to see how you make a code out of this and compare it to my own.. or i can send you a copy of my code and correct it for my benefit XD.. just reply to this post with your e.mail! thanks! C/C++..... nid help! XD here's the prob anyways.... Write a program that reads 7 scores as input and outputs the average. The program uses an array of floats. Note that you need to determine the highest and the lowest score and exclude them in the computation, assume that there are no judges giving the same score. list of scores that the judges give: 9.20 9.00 8.75 9.40 9.50 8.90 9.60 /* you can use functions on this */ /* the output would similarly look like this */ Enter the 7 scores: 9.20 9.00 8.75 9.40 9.50 8.90 9.60 Highest score: 9.60 Lowest score: 8.75 Average score: 9.20 |
|||||
|
#2
|
|
#4
|
|
I can do this but using PHP T_T. I tried C++ b4 but t'was a very long time ago
. Ok lang ang PHP? But anyways the logic will be like this.PHP Code:
regards, |
||||
|
#5
|
|
Code:
L = [9.20, 9.00, 8.75, 9.40 ,9.50, 8.90, 9.60]
for x, num in enumerate(L):
if not x: low = num
if num >= low: high = num
if num < low: low = num
if num > high: high = num
print "Highest: ", high
print "Lowest: ", low
print "Average: ", sum(L) / len(L)
Lowest: 8.75 Average: 9.19285714286 though I could use the .sort() and index it with len functions.
|
||||
|
#8
|
|
hehehe!! u guys don't read that much don't you?..
sorry again for the trouble... ps: thanks anyway for those who gave there ideas... |
|||||
|
#10
|
|
![]() epa email pa niya paul its so basic, jut keep on reading and practice.......
|
|||||
|
#11
|
|
heheh!!. sorry... i'll just show you my code and... just help me where are my mistakes..
thanks again.. and sorry for the trouble... #include <stdio.h> #define N 7 void input (float a[], int N); float highest (float a[], int N); float lowest (float a[], int N); float average (float highest, float lowest, float a[], int N); int main (void) { float a[N]; float Highest, Lowest, Average; input (a[], N); Highest = highest (a[], N); Lowest = lowest (a[], N); Average = average (Highest, Lowest, a[], N); printf ("Highest : %.2f", Highest); printf ("Lowest : %.2f", Lowest); printf ("Average : %.2f", average); } void input (float a[], int N) { int i; prinf("Enter the scores of 7 judges:"); for (1=0; i<N; i++) scanf ("%f", &a[i]); } float highest (float a[], int N) { int i; float highest; highest=a[o]; for (i=1; i<n; i++) if (highest<a[i]) highest=a[i]; return highest; } float lowest (float a[], int N) { int i; float lowest; lowest=a[0]; for (i=1; i<N; i++) if (lowest>a[i]) lowest = a[i]; return lowest; } float average (float highest, float lowest, float a[], int N) { int i; float highlow, ave, x; highlow = highest + lowest; for (i=0; i<N; i++) sum = sum + a[i]; x = sum - highlow; ave = x/5.0; return ave; } ps: i've minimized the errors in my code please HELP me on this i need it working ASAP!.. Error C:\tc2\projecti.c 3: Declaration syntax error Error C:\tc2\projecti.c 4: Declaration syntax error Error C:\tc2\projecti.c 5: Declaration syntax error Error C:\tc2\projecti.c 6: Declaration syntax error Error C:\tc2\projecti.c 13: Expression syntax in function main Error C:\tc2\projecti.c 14: Expression syntax in function main Error C:\tc2\projecti.c 15: Expression syntax in function main Error C:\tc2\projecti.c 16: Expression syntax in function main Warning C:\tc2\projecti.c 17: posible use of 'Higest' before definition in function main Warning C:\tc2\projecti.c 18: posible use of 'Lowest' before definition in function main Error C:\tc2\projecti.c 23: Declaration syntax error |
||||
|
#13
|
|
I'm not too sure about the logic but here goes. I've removed all your errors about N and n. Something like o and 0. I'm not practicing C++ by profession so I'm not sure about what you did in school but using Turbo C is quite old. Visual C++ 2003 and up is complaint to standard 99. Or better yet the GNU Compilers are good.
There is also an upcoming standard for C++ by ANSI (I think) this coming 2009. I just don't know the details. Anyway, here's your code. And oh, please use [code][/code] when posting code. Code:
#include <stdio.h>
#define N 7
void input(float a[], int n) {
printf("Enter the scores of 7 judges: ");
for (int i = 0; i < n; i++) {
scanf("%f", &a[i]);
}
}
float highest (float a[], int n) {
int i;
float highest;
highest=a[0];
for (i=1; i<n; i++)
if (highest<a[i])
highest=a[i];
return highest;
}
float lowest (float a[], int n) {
int i;
float lowest;
lowest=a[0];
for (i=1; i<n; i++)
if (lowest>a[i])
lowest = a[i];
return lowest;
}
float average (float highest, float lowest, float a[], int n) {
int i;
float highlow, ave, x, sum = 0;
highlow = highest + lowest;
for (i=0; i<n; i++)
sum = sum + a[i];
x = sum - highlow;
ave = x/5.0;
return ave;
}
int main() {
float a[N];
float Highest, Lowest, Average;
input (a, N);
Highest = highest (a, N);
Lowest = lowest (a, N);
Average = average (Highest, Lowest, a, N);
printf ("Highest : %.2f", Highest);
printf ("Lowest : %.2f", Lowest);
printf ("Average : %.2f", Average);
return 0;
}
Best Regards! |
||||
|
#14
|
|
:eek:so you can make a program in this manner......
quite confussed on the arrangement.. *heheheh* but it's ok.. thanks for the correction... hehehe compiling it now.....one more thing.... how about the prototype?> is it ok not to place a function prototype??.. |
||||
|
#15
|
|
|
||||||