+ 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;}
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;
}
0
okay thanks sm
- 1
Because your if and else statements are not included in the main function therefore not compiled.