Welcome to Dream.In.Code
Getting C++ Help is Easy!

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!

Chat LIVE With a C++ Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

Help with seating chart

2 Pages V  1 2 >  
Reply to this topicStart new topic

Help with seating chart, seating chart program

serginsurge
post 5 May, 2008 - 07:57 PM
Post #1


New D.I.C Head

*
Joined: 5 May, 2008
Posts: 9



I don't know whats wrong with the code I keep getting an error on the int j part. The program needs to
display a seating chart for a class.


CODE

#include<iostream>
#include<stdlib.h>
#include<time.h>


void main()
{
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"}},

for(int i = 0;i<=5; i++)
{
for(int j = 0,j<=4; j++)
{
cout<< student[i][j]<<"\t";
}
}
cout<<endl;
  }
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


Whizzy
post 5 May, 2008 - 08:15 PM
Post #2


D.I.C Addict

****
Joined: 11 Aug, 2007
Posts: 513

cpp
#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.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

serginsurge
post 5 May, 2008 - 08:19 PM
Post #3


New D.I.C Head

*
Joined: 5 May, 2008
Posts: 9

Thanks for the help its running now!
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Whizzy
post 5 May, 2008 - 08:30 PM
Post #4


D.I.C Addict

****
Joined: 11 Aug, 2007
Posts: 513

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
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

serginsurge
post 6 May, 2008 - 04:57 AM
Post #5


New D.I.C Head

*
Joined: 5 May, 2008
Posts: 9

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
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Whizzy
post 6 May, 2008 - 05:16 AM
Post #6


D.I.C Addict

****
Joined: 11 Aug, 2007
Posts: 513

QUOTE(serginsurge @ 6 May, 2008 - 04:57 AM) *

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...

cpp

for(int i = 0;i<=5; i++)
{
for(int j = 0,j<=4; j++)
{
cout<< student[i][j]<<"\t";
}
}
cout<<endl;
}


Row = i
seat # = J

All you have to do is put it together inside the loop...

cout << "Row "<< i
cout << "Seat "<<j


This post has been edited by Whizzy: 6 May, 2008 - 05:18 AM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

sno
post 6 May, 2008 - 05:26 AM
Post #7


New D.I.C Head

*
Joined: 4 May, 2008
Posts: 15

or if you want them to input the row and seat just take that information and use

cout << student[x][y] << endl;
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

serginsurge
post 6 May, 2008 - 03:56 PM
Post #8


New D.I.C Head

*
Joined: 5 May, 2008
Posts: 9

Thanks for the help
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

serginsurge
post 7 May, 2008 - 04:44 AM
Post #9


New D.I.C Head

*
Joined: 5 May, 2008
Posts: 9

CODE
#include<iostream>  
#include<stdlib.h>  
#include<time.h>  
using namespace std;  
  
int main(void)  
{  
    int i,j;        
typedef char seats[30];  
seats student[5][6] =  
                    {"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",
                    "Sergio","Dr","Bernardo","Millhouse","Melvin",};  

  
for(i = 0;i<5; i++){
for(j = 0; j<5; j++){
cout<< student[i][j]<<",";  
}
cout << "\n" <<endl;  
}
cout<<endl;    
cout<<endl;
strcpy (student[1][1], "Alan");
strcpy (student[2][1], "c ronaldo");
for(i = 0;i<5; i++){
for(j = 0; j<5; j++){
cout<< student[i][j]<<",";
}
cout<<"\n"<<endl;
}

for(i = 0;i<5; i++){  
for(j = 0; j<5; j++){
cout<<"row number:"<<endl;
cin>> i;
cout<<endl;
cout<<"column number:"<<endl;
cin>> j;

cout << student[i][j] << endl;  
}  
cout<<endl;  
  
  }  
  }
  


how do i make it so that it so that it tells what row a person is sitting at

example:
where is justin sitting?

justin is at row 1, seat 2
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

KYA
post 7 May, 2008 - 05:52 AM
Post #10


DIC DIC DIC DIC DIC DIC DIC DIC DIC DIC DIC DIC DIC DIC DIC DIC

Group Icon
Joined: 14 Sep, 2007
Posts: 1,318

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?
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

serginsurge
post 7 May, 2008 - 03:47 PM
Post #11


New D.I.C Head

*
Joined: 5 May, 2008
Posts: 9

i want the user to enter the name, and have it display the row and column number.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

gabehabe
post 7 May, 2008 - 04:08 PM
Post #12


D.I.C Regular

***
Joined: 6 Feb, 2008
Posts: 373

Why not use a nested for loop and check each string stored in the arrays with what the user inputted, using strcmp() smile.gif

And whizzy, you're absolutely right, it is setw(int) and is used like this:
cpp
#include <iostream>
#include <iomanip>

using namespace std;

int main ()
{
cout << setw(15) << "Hello world!" << endl;

system("pause");
return EXIT_SUCCESS;
}
One thing that you missed, however, is that you need to include <iomanip>

Hope this helps smile.gif

This post has been edited by gabehabe: 7 May, 2008 - 04:10 PM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

2 Pages V  1 2 >
Reply to this topicStart new topic
Time is now: 5/16/08 08:14AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month