The output is not properly coming....! showing garbage value for one of the arrays..! help me.....! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

The output is not properly coming....! showing garbage value for one of the arrays..! help me.....!

#include <iostream> using namespace std; class item { int icode[5]; int iprice[5]; public: void init(); void display(); void largest(); void sum(); }; void item::init() { cout<<"enter codes : "; for(int i=0; i<5; i++) { cin>>icode[5]; } cout<<" price enter : "; for(int i=0; i<5; i++) { cin>>iprice[i]; } } void item::display() { cout<<" prices are :"; for(int i=0; i<5; i++) { cout<<icode[i]<<" "<<iprice[i]<<endl; } } int main() { item books; books.init(); books.display(); return 0; }

23rd Mar 2017, 3:36 AM
Govind Choudhary
Govind Choudhary - avatar
2 Answers
+ 3
ohhhky..! thanks
23rd Mar 2017, 4:40 AM
Govind Choudhary
Govind Choudhary - avatar
+ 2
there's a mistake in initialising the icode array cout<<"enter codes : "; for(int i=0; i<5; i++) { cin>>icode[5]; } it should be : cin >>icode[i]
23rd Mar 2017, 4:12 AM
salem chriha
salem chriha - avatar