0
Why when a code fails tend to give always the same high numbers?
I made some codes and when the calculations are "bad" as ouput it always print the same numbers no matter what I put in "cin"
6 ответов
+ 1
#include <iostream>
using namespace std;
int main() {
int coef;
cin>>coef;
int V[coef];
int c ;
cin>>c;
int a;
a = V[0];
for(int i=0;i<coef;i++){
cin>>V[i];
}
for(int i=1;i<coef;i++){
cout<<a<<endl;
int a = a*c+V[i];
}
cout <<"el resto es "<<a;
return 0;
}
+ 1
Thankks!
0
The computer only does what it is told so you had to tell it to print that number. The simplest way is to print the wrong variable. But, failing to initialize the variable also works.
0
a = V[0]; puts random junk in a as you haven't stored anything in there. The a in the loop is a different one from the previous as you stated 'int a = a*c+V[I]'