+ 1

Why this doesn't output anything?

#include <iostream> #include <cstdlib> using namespace std; int main() { int m, n[m], sum, media; cout<<"how many tests did you do?"<<endl<<endl; cin>>m; int aux=m; for(int i=1;i<aux;i++){ cout<<"score in your exam "<<i<<"?"; cin>>n[m]; sum=sum+n[m]; m--; } media = sum/aux; if(media>=5){ cout<<"you passed, your media is: "<<media<<endl; } else{ cout<<"you failed, your media is:"<<media<<endl;} return 0;}

26th Mar 2017, 2:10 AM
Rafa MartĂ­nez
Rafa MartĂ­nez - avatar
3 Answers
+ 17
There are lots of problems with this code... Please refer to my fix below. #include <iostream> #include <cstdlib> using namespace std; int main() { int m; int sum = 0; int media; cout << "Input number of test : " << endl; cin >> m; int n[m]; for(int i=0; i < m; i++) { cout << "Input score "<< i +1 <<" : "; cin>>n[i]; sum=sum+n[i]; } media = sum/m; if (media >= 5) { cout << "You passed. Your media is : " << media <<endl; } else { cout << "You failed. Your media is : " << media << endl; } return 0; }
26th Mar 2017, 3:28 AM
Hatsy Rei
Hatsy Rei - avatar
0
okay thanks sm
26th Mar 2017, 11:07 AM
Rafa MartĂ­nez
Rafa MartĂ­nez - avatar
- 1
Because your if and else statements are not included in the main function therefore not compiled.
26th Mar 2017, 2:58 AM
itumeleng
itumeleng - avatar