It all works, now.
Here is some finished code if you want to see what I did. Thanks for reading this far into the post, by the way.
Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
struct node {
int x;
node *next;
};
string searchList(int, node*, node*);
void printList(node*, node*);
int main() {
node *root;
node *conductor;
int z;
srand ( time(NULL) );
z = rand() % 50;
cout << "Populating Linked list...";
cout << "Here is the number that will be looked for: " << z << endl << endl;
root = new node;
root->next = 0;
root->x = 12;
conductor = root;
for (int y = 0; y <= 50; y++) {
if ( conductor != 0 ) {
while ( conductor->next != 0) {
conductor = conductor->next;
}
}
conductor->next = new node;
conductor = conductor->next;
conductor->next = 0;
conductor->x = rand() % 50;
}
cout << searchList(z, root, conductor);
cin.get();
return 0;
}
string searchList(int y, node *root, node *conductor) {
conductor = root;
if ( conductor != 0 ) {
while ( conductor->next != 0 && conductor->x != y)
conductor = conductor->next;
}
if ( conductor->x == y )
return "Number was in the list";
else
cout << "Number not found, here are the elements of the list." << endl;
printList(root, conductor);
}
void printList(node *root, node *conductor) {
conductor = root;
if ( conductor != 0 ) {
while ( conductor->next != 0 ) {
cout << conductor->x << " ";
conductor = conductor->next;
}
cout << conductor->x << endl;
}
cin.get();
}