![]() |
Help[c++]
HI I WROTE A PROGRAM AND I WANT A HELP WITH IT PLEASE IF ANY KNOWS PROGRAMING OR HOW TO WRITE PROGRAM'S HELP ME WITH THIS,WHAT ARE THE ERRORS?: (PROGRAM ABOUT 3 FONCTIONS MOYENNE+MINIMUM+MAXIMUM OF A CLASS AND I WILL ENTER THE NOTES)
#include<iostream.h> float m,i; float z,s,y,x; double maximum(float n[30]); { for(i=1;i<=n;i++) max=n[i]; } double moyenne (float a,int n) { for(i=1;i<=n;i++) s=s+n[i]; m=s/n; } double minimum (float n[30]); { min=n[0]; for(i=1;i<=n;i++) if(n[i]<n[i-1]) min=n[i]; } int main() { float n; do{ cout<<"Entrez le nombre des eleves (maximum=30):"<<endl; cin>>n; }while(n>30); cout<<"Entrez les notes:"<<endl; for(i=1;i<=n;i++) cin>>n[i]; cout<<"La note maximal est:"<<endl; y=maximum(n[i]); cout<<y<<endl; cout<<"La note minimal est:"<<endl; z=minimum(n[i]); cout<<z<<endl; cout<<"La moyenne des notes est:"<<endl; x=moyenne(a,n); cout<<x<<endl; return 0; } |
Re: Help[c++]
i'll help you, but i need a little bit of concentration==> at home and not here at the uni.
expect an answer at night.:) |
Re: Help[c++]
Well... the code is wrong.. there's lots of mistakes...
but before i correct it, i need to know wat do u want the program to do? to you have the number of students? if so wat is it? so ur program needs to asks for the number of students. then enter the marks for each student.. get max, min, and average...??? am i right? |
Re: Help[c++]
where can i start???
Quote:
and inorder to get max, you should compare the contents of the array. somethin like Code:
double temp;Quote:
i'll explain what the function is expecting. Code:
double moyenne (float a[], int n)instead of using n[i], u should use a[i] Quote:
i'm not sure if i should give you the code i wrote, or get u to read the compiler errors, and research them so u can learn about your mistakes. Quote:
then i can just give u my code. take care |
Re: Help[c++]
Code:
#include <iostream>there is no limit for the score entered by the student... u might want to do more checks... pls understand the code or u won't get better at it.. |
Re: Help[c++]
i tried to correct your program but i got lost like hell, there are lots of mistakes in your
code, and i kept getting compiling errors even after i corrected a dozen of mistakes. but i'll criticise your work, remember that i promised to help you. first, the 3 functions you declared are not VOID, so they need a return statement, you missed all three returns. the logic in function minimum is good, or it is the best way to do it:D, but function maximum is a whole mess. use the same logic as minimum. the function moyenne needs to: set s to zero at first, or it will start as a random number. now to main; the do while statement is a mess, no need for do while at all, only write a while statement that asks for a number between 1 and 30. you need a while statement to assign each grade for the students. x, y and z are being assigned to nothing ( remember the missing return statements ). anyway there is no need to them, only use: cout<<maximum (n[i],studentnum) now let me make some remarks: to process an array with a for loop, start from i=0 and not 1, to i<arraysize and not <= arraysize. an array is passed by reference to a function when coding a function that will process an array, always think that this function will take 2 parameters at least: the array and its size. now all i have to say is that sayo did an extremely proffesional job ( remember that he is the computer engineer, and i'm still a 1st yeat comp.eng student ) and your teacher wont believe that this is your own work, so try to correct your code as much as you can, and use sayo's code for help. now a question to sayo; double* studentArray = new double[studentNum]; <<<< what is that for???? |
Re: Help[c++]
10x man 2ded ma3koun kelkoun 100/100?
:D:D lol |
Re: Help[c++]
#include<iostream>
using namespace std; double m,s; double maximum(double n[],int num) { double max; max = n[0]; for(int i=1;i<num;i++) { if ( n[i] > max ) max=n[i]; } return max; } double moyenne (double n[] , int num) { double s; for(int i=0;i<num;i++) s=s+n[i]; m=s/num; return m; } double minimum (double n[], int num) { double min=n[0]; for(int i=1;i<num;i++) if(n[i]<min) min=n[i]; return min; } int main() { int x; cout<<"Entrez le nombre des eleves (maximum=30):"<<endl; cin>>x; while(x>30 || x<1 ) cout<<"entrer un nombre qui est entre 1 et 30"; double n[x]; cout<<"Entrez les notes:"<<endl; for(int i=0;i<x;i++) { cout<<"pour l'eleve numero "<<i+1<<" :"; cin>>n[i]; } cout<<"La note maximal est:"<<maximum(n, x)<<endl; cout<<"La note minimal est:"<<minimum(n, x)<<endl; cout<<"La moyenne des notes est:"<<moyenne(n, x)<<endl; cin.get(); cin.ignore(); return 0; } and finally i managed to correct it:D:D:D:D:D:D:D |
Re: Help[c++]
Quote:
Chriseid06, i'm a Computer Engineer, but my code is really simplified... and i believe it should be suitable for a first year student, i wouldn't expect anything less from my students when i used to tutor. always make ur declarations understandable for any reader, so instead of declaring an array like this: double n[10]; you should use something like this: int array_size = 10; double studArray[array_size]; it tells the reader wat the array is created for. Quote:
Sometimes under windows (visual studio .net is wat i used) you can't create an array with variable length. so you have to create a pointer first then point it to a newly created array. i see in ur code you did the following: cout<<"entrer un nombre qui est entre 1 et 30"; double n[x]; if this compiled with you, then its great.. :) if not, then another way of doing the same thing is like wat i did. cout<<"entrer un nombre qui est entre 1 et 30"; double* n= new double[x]; Quote:
m and s should be declared in the "moyenne" function... other than this small thing, your code is very nice and neat :) ... good stuff kingroudy. |
Re: Help[c++]
sayo9394 u forgot to delete ur array.
at the end of the code: delete []studentArray; In addition I do not know if the program needs 3 functions, for now u r doing 3 for loops, the min, max and avg can be done in 1 for loop. |
| All times are GMT +1. The time now is 07:10 PM. |
Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger