C++ Question

Xenon14

Platinum Member
Oct 9, 1999
2,065
0
0
Having trouble solving the following problem:

Using array, input a name and it should output the same name. I am required to use for loop. Any solutions? Greatly appreciate it.

This is what i have so far:

void main()

{

char name[10];

cout<<&quot;enter a name:&quot;;

for (int a=0;a<=5;a++){
cin>>array[a];
}
for (int j=0; j<=5;j++){
cout<<array[5];
}

}
 

splice

Golden Member
Jun 6, 2001
1,275
0
0
Wrong forum but this is your problem.

cout<<array[5]; should be cout<<array[j];

Don't for get to include iostream.h
 

Recneps

Senior member
Jul 2, 2000
232
0
0
I don't think the for loop is need because when you use a for loop like that a person would enter the name &quot;Bob&quot; like this

Enter name:
B
o
b

with out the for loop they could enter their name on one line. I can't rember if the same is true for cout but I beleave it is.

[edit] Why are you declaring an array with 10 elements and then limiting the input to the first 5?

[edit again] You need to use cin and cout, into and out of the array you declared, &quot;name&quot;, and not the word array.
 

MasterHoss

Platinum Member
Apr 25, 2001
2,323
0
0
NOOOOOOO--no more <iostream.h>

C++ became standardized about 5 years ago--check out the REAL way to include the input/output library. Just check out other places--msdn website or whereever (unless you are allowed to use the unstandarized conventions).