Join 86,241 C++ Programmers. There are 2,284 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!
#include<iostream> #include<stdlib.h> #include<time.h> using namespace std; // needed for cout function
int main(void) // Must be int { int i,j; // moved these here while debugging typedef char seats[30]; seats student[5][5] = {"Alan","Ronaldo","pato","kaka","ronaldinho", "c ronaldo","cole","drogba","rivaldo","romario", "eduardo","affelay","nani","anderson","scholes", "clichey","kalou","deco","robinho","robben", "fabregas","ferdinand","anton","belletti","anelka"}; // You didn't need all the brackets.
for(i = 0;i<5; i++){ for(j = 0; j<5; j++){ // You have for (j=0, instead of ; cout<< student[i][j]<<"\t"; } } cout<<endl; system ("Pause"); // added a pause so you could see the display }
It compiles now... However, your display may need a little work. I would suggest you try something other than "\t". I hope this helps.
You're welcome. I would have fixed your display, but I'm unsure of the command. I think it's like setw(#) for set width.... but again, I'm not certain.
But as an after thought...
CODE
for(i = 0;i<5; i++){ for(j = 0; j<5; j++){ cout<< student[i][j]<<","; // <<<<< change to a comma here } cout << "\n" <<endl; // <<<<<<<<<<<<<<< add this here } cout<<endl; // <<<<<< You can then remove this. system ("Pause"); }
That should help a little...
This post has been edited by Whizzy: 5 May, 2008 - 08:35 PM
I need add another part to it and i have no idea how to do it, can you help me. Given a row and seat (column)number; print out the name of the student who sits at that seat. example: Who sits at row 2, seat 4? Alan
I need add another part to it and i have no idea how to do it, can you help me. Given a row and seat (column)number; print out the name of the student who sits at that seat. example: Who sits at row 2, seat 4? Alan
The answer you seek is already in your program... You're going to kick yourself when I tell you...
Depends on how you want the information to be found. Do you want the user to enter a string name or do you want the program to do it by itself with a random slot?