-
I can try but I am posting via iPhone try something like this
Code:
bool PlaceData(int );
int myarray[5000];
int main()
{
// set all values of array to -1
int value=0;
while(value != -1)
{
cout<<"Enter a value: ";
cin>>value;
if(value != -1) PlaceData(value);
}
return 0;
}
bool PlaceData(int v)
{
for(int i = 0; i < 5000;i++)
{
if(myarray[i] == -1)// open spot
{
myarray[i] = v;
return true;
}
}
return false;
}
-
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
void Displaylab(int *lab,int size)
{
int i;
for(i = 0; i < size; i++)
lab[i] = 0;
lab[i] = -1;
return;
}
int **dynArray(int row, int cols)
{
int **myPtr;
int lab[4];
myPtr = new int *[row];
for(int i = 0; i < row; i++)
myPtr[i] = new int[lab[i]];
int i = 0;
int size;
if(myPtr[i] == 0)
cout<<"empty";
return myPtr;
}
void getinput(int ID,int &Station,int &labnumb)
{
cout<<"Enter your ID number: "<<endl;
cin>>ID;
cout<<"Enter your station number: "<<endl;
cin>>Station;
cout<<"Enter your lab number: "<<endl;
cin>>labnumb;
return;
}
void logout(int **Array,int ID,int row,int lab[])
{
int r,c;
if(search(**Array,ID,row,r,c,lab)) //Here is my mistake
dynArray[r][c] = 0; //this one also.Need some help on debugging or fix it
cout<< "You have been logged out."<<endl;
return;
}
void login(int **Array,int ID,int &Station,int &labnumb)
{
getinput(ID,Station,labnumb);
Array[labnumb-1][Station-1] = ID;
return;
}
bool search(int **Array,int ID,int row,int &r,int &c,int lab[])
{
cout<<"Enter user ID to check: "<<endl;
cin>>ID;
bool found = false;
for(int i = 0; i < row;i++)
for(int j = 0; j < lab[i];j++)
if(ID == Array[i][j])
{
found = true;
r = i;
c = j;
}
return found;
}
void Menu(int **Array,int ID,int &Station,int &labnumb,int row,int &r,int &c,int lab[])
{
int choice;
cout<<"Enter 1 for login, 2 for search,3 for exit. "<<endl;
cin>>choice;
if(choice == 1)
login(Array,ID,Station,labnumb);
if(choice == 2)
search(Array,ID,row,r,c,lab);
if(choice == 3)
exit(0);
return;
}
int main()
{
int lab[4];
lab[0] = 5;
lab[1] = 6;
lab[2] = 4;
lab[3] = 3;
int **labmain;
labmain = new int*[4];
for(int i = 0; i <4 ; i++)
{
*(labmain + i) = new int;
}
labmain = dynArray(4,7);
int ID,Station,row,r,c,labnumb;
Menu(labmain,ID,Station,labnumb,row,r,c,lab);
system("PAUSE");
return 0;
}
Here is my completing code but still with some mistake and i have tried a few days to debug it but I can't understand where that mistake get wrong
-
Are we storing rows and columns that they are sitting in as well?
-
Code:
C:\Users\David\Desktop\Cboard\eric\main.cpp||In function 'int** dynArray(int, int)':|
C:\Users\David\Desktop\Cboard\eric\main.cpp|22|warning: unused variable 'size'| You are not using the variable in the function why even declare it?
C:\Users\David\Desktop\Cboard\eric\main.cpp||In function 'void logout(int**, int, int, int*)':|
C:\Users\David\Desktop\Cboard\eric\main.cpp|42|error: 'search' was not declared in this scope| Search is declared after the function you are using it in you can't do that.
C:\Users\David\Desktop\Cboard\eric\main.cpp|44|warning: pointer to a function used in arithmetic| A pointer is not a value you want to use in arithmetic a pointer is likely not the same value you want to use
C:\Users\David\Desktop\Cboard\eric\main.cpp|44|warning: pointer to a function used in arithmetic| Ditto
C:\Users\David\Desktop\Cboard\eric\main.cpp|44|error: assignment of read-only location '*(dynArray + (((unsigned int)r) + ((unsigned int)c)))'| What is dynArray? I don't even see it declared unless I am overlooking something.
C:\Users\David\Desktop\Cboard\eric\main.cpp|44|error: cannot convert 'int' to 'int**(int, int)' in assignment|
||=== Build finished: 3 errors, 3 warnings ===|
-
Hm... no really. Because In my search function i have search for the user login and save the position so that when I call function in the logout function it can search and logout the user forgot to logout
-
Code:
void logout(int **Array,int ID,int row,int lab[])
{
int r,c;
if(search(**Array,ID,row,r,c,lab)) //Here is my mistake
dynArray[r][c] = 0; //this one also.Need some help on debugging or fix it
cout<< "You have been logged out."<<endl;
return;
}
when you call search you are not passing your array by using the double ** in the function call. Do keep that in mind.
Code:
dynArray[r][c] = 0;
Umm it is a function what are you trying to do call the function?
Maybe use:
-
I wondering the second part I'm calling the position of the user login in the search function. And it isn't like this dynArray[][]= 0?
Code:
if(search(Array,ID,row,r,c,lab))
It still got the syntax error in no matching function call
-
Move search function declaration above the logout declaration.
-
It still doesn't work. The syntax error said non-value assismentT_T
-
OH, in that case:
Move the search function declaration above the logout declaration. Then post the updated code and actual copy-and-paste of the error message.
I see lots of new in your program, but no delete. Figure out how and when you are going to delete stuff and you will solve more of your problem.
-
Here is the new code with the non-lvalue in assignment
Code:
#include <iostream>#include <cstdlib>
using namespace std;
void Displaylab(int *lab,int size)
{
int i;
for(i = 0; i < size; i++)
lab[i] = 0;
lab[i] = -1;
return;
}
int **dynArray(int row, int cols)
{
int **myPtr;
int lab[4];
myPtr = new int *[row];
for(int i = 0; i < row; i++)
myPtr[i] = new int[lab[i]];
int i = 0;
int size;
if(myPtr[i] == 0)
cout<<"empty";
return myPtr;
}
void getinput(int ID,int &Station,int &labnumb)
{
cout<<"Enter your ID number: "<<endl;
cin>>ID;
cout<<"Enter your station number: "<<endl;
cin>>Station;
cout<<"Enter your lab number: "<<endl;
cin>>labnumb;
return;
}
void login(int **Array,int ID,int &Station,int &labnumb)
{
getinput(ID,Station,labnumb);
Array[labnumb-1][Station-1] = ID;
return;
}
bool search(int **Array,int ID,int row,int &r,int &c,int lab[])
{
cout<<"Enter user ID to check: "<<endl;
cin>>ID;
bool found = false;
for(int i = 0; i < row;i++)
for(int j = 0; j < lab[i];j++)
if(ID == Array[i][j])
{
found = true;
r = i;
c = j;
}
return found;
}
void logout(int **Array,int ID,int row,int lab[])
{
int r,c;
if(search(Array,ID,row,r,c,lab))
dynArray(r,c) = 0;
cout<< "You have been logged out."<<endl;
return;
}
void Menu(int **Array,int ID,int &Station,int &labnumb,int row,int &r,int &c,int lab[])
{
int choice;
cout<<"Enter 1 for login, 2 for search,3 for exit. "<<endl;
cin>>choice;
if(choice == 1)
login(Array,ID,Station,labnumb);
if(choice == 2)
search(Array,ID,row,r,c,lab);
if(choice == 3)
exit(0);
return;
}
int main()
{
int lab[4];
lab[0] = 5;
lab[1] = 6;
lab[2] = 4;
lab[3] = 3;
int **labmain;
labmain = new int*[4];
for(int i = 0; i <4 ; i++)
{
*(labmain + i) = new int;
}
labmain = dynArray(4,7);
int ID,Station,row,r,c,labnumb;
Menu(labmain,ID,Station,labnumb,row,r,c,lab);
system("PAUSE");
return 0;
}