i am just confused.

how can i print the no of entried and price?

1
2
3
4
5
6
7
8
9
10
11
  for(int i=0;i<3; i++){
		cout<<"enter the entries"<<endl;//help me in this portion,first loop for house entries
		cin>>avalible[i];
	}
	{

		for(int j=0;j<3;j++)//this loop is for price.
			cin>>avalible[j];
	}
	}
cout<<"the house entries and price is"<<avalible[i][j];//i am confused here,i and j is giving error.what i should add instead of i and j here? 
closed account (o3hC5Di1)
Hi there,

Your last line is outside of the {}-braces of your for-loop. Hence, i and j do not exist anymore at that point.
Also, you will probably need two separate arrays (or create a struct for a house), one for prices and one for houses:

1
2
3
4
5
6
7
8
9
10
11
 std::string houses[3];
int prices[3];

for (int i=0; i<3; ++i)
{
   std::cout << "Enter house: ";
   std::cin >> houses[i];

   std::cout << "Enter price: ";
   std::cin >> prices[i]
}


I'll leave it up to you to figure out how to output the result to the user :)
Let us know if you require any further help.

All the best,
NwN
i wirote a program in which i declare a class called house info,i am having trouble of displaying no of house entries and things.i have declard an array name avalible[3],it gets input in function getdat() but not giving any output.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class houseInfo
{
	string ownersName;
	string adress;
	int bedrooms;
	long int price;
	string avalible[3];
public:
	void getdata();
	void display();
};
void houseInfo::getdata()
{
	int value;
	cout<<"Enter The Owner's Name"<<endl;
	cin>>ownersName;

	cout<<"Enter The Adress"<<endl;
	cin>>adress;

	cout<<"Enter The Bedrooms"<<endl;
	cin>>bedrooms;

	cout<<"Enter The Price"<<endl;
	cin>>price;
	cout<<"enter the house entires and price"<<endl;
	
	for(int i=0;i<3; i++){
		cin>>avalible[i];

	}
	{
		for(int j=0;j<3;j++)
			cin>>avalible[j];
	}
	}
void houseInfo::display()
{
	cout<<"The Name Of The Owner Is"<<' '<<ownersName<<endl;


	cout<<"The Adress Of The Employer Is"<<' '<<adress<<endl;


	cout<<"The Number Of Bedrooms Are"<<' '<<bedrooms<<endl;


	cout<<"The Price Of The House Is"<<' '<<price<<endl;
	cout<<"the house entries and price is"<<avalible;//i am confused here,i and j is giving error.what i should add instead of i and j here?
	
}
int main(){
	houseInfo house;
	cout<<"\t \t \t Wellcome To Information System"<<endl;
	cout<<"\t \t \t -----------------------------"<<endl<<endl;

	house.getdata();

	house.display();
	getch();
	return 0;
}

@Mehdinaqvi what is the exact error code you get ?
------------------------------------------------
Your other errors:

1
2
3
4
5
6
7
8
for(int i=0;i<3; i++){
		cin>>avalible[i];
}
	{ // you have an extra brace here i think you want to put this beside the for loop below
		for(int j=0;j<3;j++) // I think you want a curly brace here '{'
			cin>>avalible[j];
	 }
	} // you also have an extra brace here 

you overwrite the data you have just stored in available, i think you want a separate array for the price of the houses


cout<<"the house entries and price is"<<avalible;
I think you want to print the contents of the array available which should be accessed by available[0] ...and so on
In that case, you want to put it inside a for loop
Last edited on
Topic archived. No new replies allowed.