Trouble Printing an Array

May 18, 2014 at 7:53pm
I'm having issues printing out the array. I have to take it in in the main and print it out in a function. A quick explanation would be great! Thank you.

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
#include <cstdlib>
#include <iostream>
#include <conio.h>

using namespace std;

void print(char [5][80]);

int main()
{
    char names[5][80];
    int w=1;
    cout<<"You have entered the baseball stats program."<<endl;
    do
    {
               for(int x=0;x<5;x++)
               {
                       cout<<"Enter a players name>> ";
                       for(int y=0;y<80;y++)
                       {
                               names[x][y]=getch();
                               cout<<names[x][y];
                               if(names[x][y]==13)
                               {
                                                  names[x][y]==32;
                                                  cout<<endl;
                                                  break;
                                                  }
                               
                                       }
                                       }
               print(names);
               do
          {
                                    cout<<"Enter 1 to continue or 2 to quit>> "<<endl;
                                    cin>>w;
                                    }while((w!=1)&&(w!=2));
                                    }while((w==1)||(w!=2));
            
    
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

char print(char names)
{
          for(int x=0;x<5;x++)
          {
                          for(int y=0;y<80;y++)
                          {
                                           cout<<names[x][y];
                                           }
                                           }
}
May 18, 2014 at 8:00pm
names[x][y]==32; on line 25. Why do you have comparison happening here?

1
2
3
4
5
6
7
8
9
10
char print(char names[][80]) // <-- should look like this as you must include dimensions and any sizes except the first.
{
          for(int x=0;x<5;x++)
          {
                          for(int y=0;y<80;y++)
                          {
                                           cout<<names[x][y];
                                           }
                                           }
}


EDIT: You also have a return value on this function but not your declaration.

EDIT: using system("PAUSE") is also highly discouraged as it has many problems associated with it. And the more experienced programmers will snarl when they see this.
Last edited on May 18, 2014 at 8:22pm
Topic archived. No new replies allowed.