Join 118,923 C++ Programmers for FREE! Ask your question and get quick answers from experts. There are 1,947 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!
i need to display the row; i need suggestion how to do it, here' waht i have
CODE
#include<iostream> #include<iomanip> using namespace std; void display_draw(int mega[12][6], int draw_index); int main()
{ int i=0,j; const int NUMROWS=12; const int NUMCOLS=6; int draw_index; int val[NUMROWS][NUMCOLS]={ 5,14,16,39,51,34, 1,20,22,29,41,35, 1,3,12,19,20,28, 1,22,33,43,52,36, 8,14,22,39,50,44, 10,22,36,50,53,39, 11,17,25,36,42,13, 5,14,25,47,49,36, 8,9,14,38,44,36, 3,5,15,43,51,11, 8,9,43,44,54,27, 4,19,24,32,54,5};
//display(vals) cout<<"please put in row"<<endl; cin>>NUMROWS[i]; display_draw(int val[12][6], int draw_index) return 0; } void display_draw(int mega[12][6], int draw_index) {int i=0; for(i=0;i<NUMROWS;i++) { if(NUMROWS[i]==draw_index) cout<<endl;
#include<iostream> #include<iomanip> using namespace std; void display_draw(int mega[12][6], int draw_index); int main()
{ int i=0,j; const int NUMROWS=12; const int NUMCOLS=6; int draw_index; int val[NUMROWS][NUMCOLS]={ 5,14,16,39,51,34, 1,20,22,29,41,35, 1,3,12,19,20,28, 1,22,33,43,52,36, 8,14,22,39,50,44, 10,22,36,50,53,39, 11,17,25,36,42,13, 5,14,25,47,49,36, 8,9,14,38,44,36, 3,5,15,43,51,11, 8,9,43,44,54,27, 4,19,24,32,54,5};
//display(vals) cout<<"please put in row"<<endl; cin>>NUMROWS[i]; display_draw(int val[12][6], int draw_index) return 0; } void display_draw(int mega[12][6], int draw_index) {int i=0; for(i=0;i<NUMROWS;i++) { if(NUMROWS[i]==draw_index) cout<<endl;
return; }
Firstly your declaring NUMROWS const so cin << NUMROWS[i]; on line 28 wont work. it's also not an array so you should try just cin << i; or cin << draw_index; which is what you probably intended.
Secondly on line 29 your redeclaring val and draw_index so take out the int beforehand and replace draw_index with i or just draw_index because that is the row that the user wants to display.
Also in your display_draw definition your first parameter is mega yet you reference NUMROWS[i] which hasnt been declared.
Most of the errors here are pretty simple and could probably be found when you try to compile. If you didn't debug your compile errors and want to be a serious programmer then your gonna have to start doing it yourself. It comes with the territory
step 1: write code step 2: compile code step 3: fix errors step 4 repeat steps 2-3 until program works
i changed the main function , which has no errors, but the function still errors which i am kind a confuse , can't debug until the program is totally error free. Just give me sugggestiion, where i am wrong, so i can fix it ,
CODE
#include<iostream> #include<iomanip> using namespace std; void display_draw(int mega[12][6], int draw_index); int main()
{ //int i; const int NUMROWS=12; const int NUMCOLS=6; int draw_index; int val[NUMROWS][NUMCOLS]={ 5,14,16,39,51,34, 1,20,22,29,41,35, 1,3,12,19,20,28, 1,22,33,43,52,36, 8,14,22,39,50,44, 10,22,36,50,53,39, 11,17,25,36,42,13, 5,14,25,47,49,36, 8,9,14,38,44,36, 3,5,15,43,51,11, 8,9,43,44,54,27, 4,19,24,32,54,5};
cout<<"please put in row"<<endl; cin>>draw_index; display_draw(val,draw_index); return 0; } void display_draw(int mega[12][6], int draw_index) {int i; for(i=0;i<mega[12];i++) { if(mega[i]==draw_index) cout<<endl; }
You can debug your compile errors. Just follow the four steps I provided in my earlier post because this really is an essential part of programming and if you don't start now at the beginning then you'll make a horrible programmer.
I have revised your codes. I eliminate the display_draw function. I'm not sure if this what you want.
CODE
#include<iostream> using namespace std;
int main() {
const int NUMROWS=12; const int NUMCOLS=6; int draw_index; int val[NUMROWS][NUMCOLS]={ 5,14,16,39,51,34, 1,20,22,29,41,35, 1,3,12,19,20,28, 1,22,33,43,52,36, 8,14,22,39,50,44, 10,22,36,50,53,39, 11,17,25,36,42,13, 5,14,25,47,49,36, 8,9,14,38,44,36, 3,5,15,43,51,11, 8,9,43,44,54,27, 4,19,24,32,54,5};
int row, colum; cout<<"Number of rows"<<endl; cin>>row; cout<<"Number of columns"<<endl; cin>>colum; //Display now. for(int i=0;i<row;i++) { for (int j=0; j<colum; j++) { cout << val[i][j]<<","; } cout <<"\n"; }
return 0; }
First of all you cannot use the local variables from other function to another. Hence you cannot use the val array to the display_draw function. Since you use mega array and this is empty you get error of this.
If you want to use val array variable, then you need to move it within the display_draw function not in main function.
Other option:
CODE
#include<iostream> using namespace std;
//Display now. void display_draw(int row, int colum) { const int NUMROWS=12; const int NUMCOLS=6; int draw_index; int val[NUMROWS][NUMCOLS]={ 5,14,16,39,51,34, 1,20,22,29,41,35, 1,3,12,19,20,28, 1,22,33,43,52,36, 8,14,22,39,50,44, 10,22,36,50,53,39, 11,17,25,36,42,13, 5,14,25,47,49,36, 8,9,14,38,44,36, 3,5,15,43,51,11, 8,9,43,44,54,27, 4,19,24,32,54,5}; for(int i=0;i<row;i++) { for (int j=0; j<colum; j++) { cout << val[i][j]<<","; } cout <<"\n"; } } //driver program int main() { int row, colum; cout<<"Number of rows"<<endl; cin>>row; cout<<"Number of columns"<<endl; cin>>colum; display_draw(row, colum);