# TOPIC

Runtime error

#### Mehedi Hasan asked 10 months ago

//Can anyone tell why i'm getting runtime error?

include include

using namespace std; int main() { int n; float a,b,c; float sum[200]; cin>>n; for(int i=0; i<n; i++) { cin>>a>>b>>c; sum[i] = (((a2.0)+(b3.0)+(c*5.0))/10); } for(int i=0; i<n; i++) { cout<<fixed<<setprecision(1)<<sum[i]<<"\n"; } }

Remember not post solutions. Your post may be reviewed by our moderators.

• #### Rafael Ziliarski replied 10 months ago

Meu código, foi aceito:

include include include include

using namespace std;

int N;

int main(){ cin >> N; double vetor[N],somatorio[N],somatorio1[N],somatorio2[N],total[N]; for(int i=0;i<N;i++){ cin>>vetor[0]>>vetor[1]>>vetor[2]; somatorio[i]=(vetor[0]2)/10; somatorio1[i]=(vetor[1]3)/10; somatorio2[i]=(vetor[2]*5)/10; total[i]=somatorio[i]+somatorio1[i]+somatorio2[i]; } for(int j=0;j<N;j++){ cout<<setprecision(1)<<fixed<<total[j]<<endl; } return 0; }

• #### Tarcísio Mazur Junior replied 10 months ago

You do not have the value of N, it can be 10 or even 1000000. You can read the information and print without the need for a vector, or declare float sum[1000000]. It's possible to use vectors in c++ with no defined size:

``````#include <vector>
int main(){
vector<float> sum;
for(int i=0; i<n; i++){
...
sum.push_back(value);
}
///To print use for each
for(auto g: sum)
cout << g << endl;
/// Or normal for
for(int i=0; i<n; i++)
cout << sum[i] << endl;
return 0;
}``````