storing input value in an array

I want the user to make 5 accounts with 5 different passwords and for them to get stored in an array and then prints out all the accounts and passwords registered. However I do that by this code and it only prints out the number of the 4th account 5 times. What am i doing wrong.

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
#include<iostream>
#include<iomanip>


int main()
{
const int row = 5;
const int column=5;

int array[column][row];

int count = 0;
int account;
int password;

while ( count < 5)
{
    std::cout<<"Enter account number: ";
    std::cin>>account;

    std::cout<<"Enter account password: ";
    std::cin>>password;

    for(int i = 0; i < 5; i++)
        array[i][i]= account,password;


count++;
}
std::cout<<"Account number"<<"              "<<"Account Password"<<std::endl;

for(int j= 0; j < 5; j++)
std::cout<<array[j][j];
std::cout<<std::endl;


}
your array should only have 10 elements.
also make sure that you enter purely numerical values for both the account name and password as you delclare:
int account;
int password;

here is the code. your code only needed minor corrections.

#include<iostream>
#include<iomanip>


int main()
{
const int row = 5;
const int column=2;

int array[column][row];

int count = 0;
int account;
int password;

while ( count < 5)
{
std::cout<<"Enter account number: ";
std::cin>>account;

std::cout<<"Enter account password: ";
std::cin>>password;


array[count][0]= account;
array[count][1]= password;


count++;
}
std::cout<<"Account number"<<" "<<"Account Password"<<std::endl;

for(count= 0; count < 5; count++)
{
std::cout<<array[count][0]<<" "<<array[count][1]<<std::endl ;
}
system ("pause");
}
Last edited on
try this.

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
#include<iostream>
#include<iomanip>


int main()
{
const int row = 5;
const int column=5;

int array[column][row];

int count = 0;
int account;
int password;


while(count < 5)
{
   std::cout<<"Enter account number: ";
    std::cin>>account;

    std::cout<<"Enter account password: ";
    std::cin>>password;
	
	array[count][0] = account;
	array[count][1] = password;

	count++;
}

std::cout<<"Account number  Account Password"<<std::endl;

// loop for row
for (int i =0; i < 5; i++)
{
        // for column
	for(int j = 0; j < 2; j++)
	{
		std::cout << array[i][j] << " ";
	}
std::cout<<std::endl;
}

// wait for user input then close app.
int x;
std::cin >> x;
return 0;
}
Thanks a lot I tried that and it worked.
Topic archived. No new replies allowed.