I am using this as an example to show what I want to do.
I have already done a char array like this:

char name[10][10] = {"1. One",
"2. Two",
"3. Three",
"4. Four", etc.. down to 24.

I have already wrote the code, so all these 24 subarrays can be shown.
The program then asks the user which number they want, and the user then inputs this.

What I want to do is to later show the user what number they put into the program, with a cout line: cout <<"Name Number" << name_Number;

But I can't as I am not sure how to declare the 1. One, 2.Two etc.., under the name_number,

Also When I ask the user the question they only input 1, 2 or 3 (the number not the name) etc, as later it then displays "1. One" showing the user what they have put into the program previosly, I'm just not sure how to do this, any help will be appreciated.

Can you paste the code that you have written so far?

Can you paste the code that you have written so far?

#include<iostream.h>
#include<windows.h>


int count =0;
int choice = 0;
int number = 0;


int main()
{
char name[20][20] = {"1. One",
"2.Two",
"3.Three",
"4. Four",
"5. Five",
"6. Six",
"7. Seven",
"8. Eight",
"9. Nine",
"10. Ten",
"11. Eleven",
"12. Twelve",
"13. Thirteen",
"14. Fourteen",
"15. Fifteen",
"16. Sixteen",
"17. Seventeen ",
"18. Eighteen ",
"19. Nineteen",
"20. Twenty",
"21. Twenty one",
"22. Twenty two",
"23. Twenty three",
"24. Twenty Four",
};
do
{
system ("cls")
for(count =0; count <= 24;count ++)
{
cout <<name[count] <<endl;
}
cout<<"Please enter Number: ";
cin >> number
}while (number < 1 || number > 24);


cout <<"Number:  " << number; ---->>> << cout << "Name: " << name_number; <--
(This is where I want the other part)


Sleep (1500000);


return 0;
}

First, you need to get the size of your array right. A 20x20 array of char doesn't hold 24 strings. It holds 20 strings that are up to 19-char long.

As Fbody mentioned, change the size of your array accordingly. To output any type of array, especially two dimensional, use for loops.

#include <iostream>
using namespace std;

int main () {


	char name[20][20] = {"1. One",
"2.Two",
"3.Three",
"4. Four",
"5. Five",
"6. Six",
"7. Seven",
"8. Eight",
"9. Nine",
"10. Ten",
"11. Eleven",
"12. Twelve",
"13. Thirteen",
"14. Fourteen",
"15. Fifteen",
"16. Sixteen",
"17. Seventeen ",
"18. Eighteen ",
"19. Nineteen",
"20. Twenty"

};

	int number;

	cout << "Enter the number, I will repeat after you.\n";
	cin >> number;

	for(int index = 0; index < number; index++){
		cout << name[number-1][index];
	}

	return 0;

}

Yes I know about that part about changing the [20] [20], but am sure what else to do, regarding the last part

I just wrote it. You can copy and paste what I wrote and build it. It should work for you. You may want to toss your while loop back in there to check to make sure that the input is valid, between 1 and array size-1.

// This part, as copied and pasted from my previous note, will output the desired array to cout.

for(int index = 0; index < number; index++){
cout << name[number-1][index];
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.