+ 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; }
2 odpowiedzi
+ 3
ohhhky..! thanks
+ 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]