I am new with C++, so I need your help. I wrote this program,
#include<iostream.h>
int main(){
int totalAge = 0;
int age[10];
for(int j= 1; j<10; j++){
age[j] = j;
cout << age[j] << endl;
}
for(int i = 0; i<10; i++){
totalAge = age[i];
cout << "Total Age is : " << totalAge << endl;
}
system("pause");
}
Where as the output on command prompt is this:
1 2 3 4 5 6 7 8 9
Total Age is : 1700868285
Total Age is : 1
Total Age is : 2
Total Age is : 3
Total Age is : 4
Total Age is : 5
Total Age is : 6
Total Age is : 7
Total Age is : 8
Total Age is : 9
Press any key to continue . . .
The only thing I want to know is that why is first "Total Age is : 1700868285" I believe it should be "Total Age is : 0" Please explain it. Thanks
iostream.his not a standard header. Useiostream.<iostream.h>; @chris is not quite accurate - it is a standard header, it is merely deprecated in favour of<iostream>. Using the preferred header form would also require scope resolution tostd::for all iostream symbols (e.g.std::cout). There is always a chance you are using some ancient compiler that does not support namespaces.