RayvenHawk 22 Junior Poster in Training

I figured it out, thanks though. I had to use the screen height & widith for bottom & right (since their initial value is not 0), when that condition is met the value for those go in the opposite direction causing it to stop moving in that direction. Then for top & left I stated that if top or left equalled 0 then their values changed the same way the others did, which prevented it from going further in that direction.

if (KEY_DOWN(VK_DOWN))
	{
		d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
		rect2.top = rect2.top + 1;
		rect2.bottom = rect2.bottom + 1;

		if (rect2.bottom > SCREEN_HEIGHT)
		{
			rect2.top = rect2.top - 1;
			rect2.bottom = rect2.bottom - 1;
		}
	}
	if(KEY_DOWN(VK_UP))
	{
		d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
		rect2.top = rect2.top - 1;
		rect2.bottom = rect2.bottom - 1;

		if (rect2.top == 0)
		{
			rect2.top = rect2.top + 1;
			rect2.bottom = rect2.bottom + 1;
		}
	}
	if(KEY_DOWN(VK_RIGHT))
	{
		d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
		rect2.left = rect2.left + 1;
		rect2.right = rect2.right + 1;

		if(rect2.right > SCREEN_WIDTH)
		{
			rect2.right = rect2.right - 1;
			rect2.left = rect2.left - 1;
		}
	}
	if(KEY_DOWN(VK_LEFT))
	{
		d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
		rect2.left = rect2.left - 1;
		rect2.right = rect2.right - 1;

		if(rect2.left == 0)
		{
			rect2.left = rect2.left + 1;
			rect2.right = rect2.right + 1;
		}
	}
RayvenHawk 22 Junior Poster in Training

I'm working on an assignment that I need to move a sphere around the screen with the keyboard arrows. I got the movements working and all that. But I'm drawing a blank on an "if" statement to prevent the image from going off the screen when the edges are reached.

if (KEY_DOWN(VK_DOWN))
	{
		d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
		rect2.top = rect2.top + 1;
		rect2.bottom = rect2.bottom + 1;

		if (rect2.bottom > SCREEN_HEIGHT)
		{
			rect2.bottom = - 1;
		}
	}
RayvenHawk 22 Junior Poster in Training

Here the code I currently have for the image. What it does right now is flashes new images on the screen instead of making the single image float around the screen.

void DrawBitmap(HDC hdcDest, char *filename, int x, int y)
{
    HBITMAP image;
    BITMAP bm;
	HDC hdcMem;

    //load the bitmap image
    image = (HBITMAP)LoadImage(0,"asteroid.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);

    //read the bitmap's properties
    GetObject(image, sizeof(BITMAP), &bm);

    //create a device context for the bitmap
    hdcMem = CreateCompatibleDC(global_hdc);
	SelectObject(hdcMem, image);

    //draw the bitmap to the window (bit block transfer)
    BitBlt( 
        global_hdc,              //destination device context
        x, y,                    //x,y location on destination
        bm.bmWidth, bm.bmHeight, //width,height of source bitmap
	    hdcMem,                  //source bitmap device context
        0, 0,                    //start x,y on source bitmap
        SRCCOPY);                //blit method

    //delete the device context and bitmap
    DeleteDC(hdcMem);
    DeleteObject((HBITMAP)image);
}


void Game_Init()
{
    //initialize the game...
    //load bitmaps, meshes, textures, sounds, etc.

    srand(time(NULL));
}

void Game_Run()
{
    //this is called once every frame
    //do not include your own loop here!
    
    int x = 0, y = 0;
    RECT rect;
    GetClientRect(global_hwnd, &rect);
	
    if (rect.right > 0)
    {
        x = rand() % (rect.right - rect.left);
        y = rand() % (rect.bottom - rect.top);
        DrawBitmap(global_hdc, "asteroid.bmp", x, y);
    }
}
RayvenHawk 22 Junior Poster in Training

Ok I have a problem here. I'm in my game engine class and for some unknown forsaken reason they decided to teach console c++ then jump to c# for windows apps, then back to c++ to do directx apps, so my skills with c++ and windows apps is well krappy. So I'm trying to learn as quick as possible.

Anyway on to my question, this weeks assignment is we need to load up a bitmap (already did that) and have it float around the screen slowly. I'm only able to get it to constantly load the image so it remebles more of an asteroid belt than a single rock floating in the window.

I'm assuming that DrawBitmap is probably the wrong way to go with this, but not sure. What function do I need to call to acomplish getting the image to move around the screen?

RayvenHawk 22 Junior Poster in Training

The Below Code might Help just remember MessageBox Returns the Value just store that Value and then Process that response rather than calling the message box again and again.

int nResponse = MessageBox(NULL, TEXT("Hello, World"), TEXT("Say Yes No Cancel"), MB_YESNOCANCEL);

	if (nResponse == IDYES) {
		MessageBox(NULL, TEXT("Hey You Pressed Yes!"), TEXT("Wow! Got It"), MB_OK |MB_ICONEXCLAMATION);
	}
	/*else if(...) {
	}
	else if (...) {
	}*/

One more thing why if (....) and if (....) two times, if you notice your code, you'll find one more thing
you check the first condition then again you check for some other condition.
why is that so, logically and as per the requirement, you just need to show the form & store it response & then process that response rather than calling the MessageBox API again and again.


Hope this might help

Thanks a lot. That helped out perfectly. This is my first week using C++ in a win32 sense so I'm trying to get out of console thought and move on. Good thing is after my next assignment I get to start dealing with DirectX so that'll be interesting.

Thanks for yor help, much appreciated.

RayvenHawk 22 Junior Poster in Training

I'm doing an assignment for class and we're suppose to write a program that pops up a window with YES/NO/CANCEL buttons and when the user pushes a button another window pops up displaying what button they clicked.

I wrote up the code and it does work, but it takes several clicks of the button for it to finally display the 2nd box. Any reason for this??

#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInstance, LPSTR lpCmdLine, int nSHowCmd)
{
	MessageBox(NULL, "This is my dialog box", "Dialog Box",MB_YESNOCANCEL | MB_ICONEXCLAMATION);
	if (MessageBox(NULL, "This is my dialog box", "Dialog Box", MB_YESNOCANCEL | MB_ICONEXCLAMATION) == IDYES)
	{
		MessageBox(NULL, "User Clicked Yes", "Robert Week 1", MB_OK | MB_ICONEXCLAMATION);
	}
	if (MessageBox(NULL, "This is my dialog box", "Dialog Box", MB_YESNOCANCEL | MB_ICONEXCLAMATION) == IDNO)
	{
		MessageBox(NULL, "User Clicked No", "Robert  Week 1", MB_OK | MB_ICONQUESTION);
	}
}
RayvenHawk 22 Junior Poster in Training

I'll clean up the code tomorrow, and I'll try the while command. I was thinking of the do/while but am unsure if while in the sub-menus if they'll quit back to the main one or not. I'll update tomorrow when I try it.

RayvenHawk 22 Junior Poster in Training

hmmm im really stuck

First off I agree with VernonDozier, just divide your percentage value by 100 to get a decimal.

#include<iostream>
#include<iomanip>
#include<string>
using namespace std;

int main()
{
	int ticketssold, percentticket, moneyprizes;
	string charity;

	cout <<"1.Number of tickets sold?: ";
	cin >> ticketssold;

Where is the variable to contain the value for each ticket sold?? You can't generate a percentage without a value to go along with it.

cout <<"2.What percentage of the ticket revenue goes to administrative costs?: ";
	cin >> percentticket;

For this you can add another int called percent (or whatever you want and add the following
percent = percentticket / 100;

But again without having an int variable that totals up the actual revenue from ticket sales, the above is pointless.

cout <<"3.How much total money is distributed in prizes?: ";
	cin >> moneyprizes;

	cin.ignore();

	cout <<"4.What is the name of the charity?: ";
	getline(cin,charity);

	cout << left <<"Charity:" << right << setw(50) << charity << endl;
	cout << left <<"Revenue generated from ticket sales:" << right

You are display text, but not calling up the variables that have your data stored for the ticket sales, that is kinda important to have, otherwise the user will never know the actual answer.

RayvenHawk 22 Junior Poster in Training

There's a few solutions to that 'problem'. I usually try and keep the clutter out of main by putting all the meat and bones of main() into functions and only using main to call them, and potentially have a loop (which would return you to the first menu for example). This, however, is a bit worse for resources than using a switch statement with all the code inside of each case. I, personally, would be more conscerned with getting the binary tree working :P

Actually all of my data structures function in their seperate programs (including the binary tree). I created a pointer to the submenu on main within the switch statements: i.e

switch (m_select)
case 1:
{
stackmenu();
break;
}

I ran the program and the stack program is complete and functions correctly (except when I exit, it proceeds to crash, but thats not important at the moment).

So if I call the menus up within the switch statements how would I get those sub menus to terminate and return to the actual main menu?

Here is my main menu code (seeing what I have may help)

#include "binaryTreeSearch.h"
#include "mystack.h"
#include "queuetype.h"
#include "menu_display.h"
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int m_select;
	menu_display menu;

	cout << "Final Project Program" << endl;
	cout << endl;
	cout << "1) Stack Data Structures" << endl;
	cout << "2) Queue Data Structures" << endl;
	cout << "3) Binary …
RayvenHawk 22 Junior Poster in Training

Perhaps consider a menu using a switch case construction?

Ok I decided that to organize the main menu better and make the code look nicer I went with the switch commands. But that doesn't resolve my initial problem. When I for example select stacks, I can do whatever I want within that piece of the program, but as soon as I choose to exit, it completely exits the entire program. I want it to revert back to my main menu.

It's not a requirement, but I'm aiming for a 100%, that'll give me a 89% in the class.

RayvenHawk 22 Junior Poster in Training

Ok I'm doing my final project for my Data Structures class and have a quick question. This hasn't come up in any of my programming classes yet (which now that I think about it, is kind of odd but oh well).

What I'm having to do is write an interactive program allowing the user to access 3 different data structures. That part I have no problems with (going to use Stacks, Queues & Binary Tree). What I'm wanting is to have the main menu display:

1) Use Stacks
2) Use Queues
3) Use Binary Tree
4) Exit Program

then it goes into the submenu for that option.

What I need is to reset the program so when they finish with that data structure it brings them back to the main menu.

Here is what I'm thinking should work, am I right or do I need to go about it differently?

do
{
    " Display main menu here"

      if (option 1 is picked)
       {
           do
              {
                 "Display menu for selection"
                 run program
              }
              while (user does not select to exit)
        }

      if (option 2 is picked)
       {
          do
             {
                "same as option 1"
              }
          while (user doesnt select to exit)
       }

}
while (user doesn't select to quit entire program)

Now before everyone starts to nit pick at my code, it's just a shell to give you an idea of what I want to do.


Thanks

RayvenHawk 22 Junior Poster in Training

Thanks a ton Sci@phy. I managed to figure out where my flaw was. I was trying to call the function from main without any values, but my function needed values in order to work.

Problem was I couldn't seem to reference "root" in the main program. Even though it exists in BinaryTree.h.

So what I did was use the same scheme as printTree (which is have 2 void functions, one w/ values & one that calls that function up). And viola! it works great.

Here is what I did.

template<class elemType>
void binaryTreeType<elemType>::swapSubtreeNodes()
{
	swapSubtreeNodes(root); // display new root
}

template<class elemType>
void binaryTreeType<elemType>::swapSubtreeNodes(nodeType<elemType> *p)
{
	nodeType<elemType> *root; //create pointer for root
	nodeType<elemType> *temp; //create pointer for temp
   if (p==NULL) 
   {
      return;
   }
   else 
   {

      // do the subtrees
	  swapSubtreeNodes(p->llink);
      swapSubtreeNodes(p->rlink);
      // swap the pointers in this node
      temp = p->llink;
      p->llink = p->rlink;
      p->rlink = temp;
	
   }
	   root = temp; // set root to equal temp
}

In main I just call tree.swapSubtreeNodes();. The formatting was sucky, but I'm not concerned with that.

You were a great help, very much appreciated. Thank god this term is almost over, I HATE this Data Structures class.

RayvenHawk 22 Junior Poster in Training

Ok here is what I have now:

Header file

template<class elemType>
void binaryTreeSearch<elemType>::insert(const elemType &insertItem)
{
	nodeType<elemType> *current;
	nodeType<elemType> *trailCurrent;
	nodeType<elemType> *newNode;

	newNode = new nodeType<elemType>;
	newNode->info = insertItem;
	newNode->llink = NULL;
	newNode->rlink = NULL;

	if (root == NULL)
		root = newNode;
		root = &temp;
	else
	{
		current = root;

		while (current != NULL)
		{
			trailCurrent = current;

			if (current->info == insertItem)
			{
				cout << "The item to be inserted is already in the tree ";
				cout << "duplicates are not allowed." <<endl;
				return;
			}
			else if (current->info < insertItem)
				current = current->llink;
			else
				current = current->rlink;
		}

		if (trailCurrent->info < insertItem)
			trailCurrent->llink = newNode;
		else
			trailCurrent->rlink = newNode;
	}
}

I typed in "tree.swapSubtreeNodes(root);"

But when I compile it tells me it's an undeclared value.

RayvenHawk 22 Junior Poster in Training

ok stupid question, but I'm drawing a blank on how to reference the root node in the main fnc. I assumed it'd be "tree *root", but it comes back and tells me root is undefined.

RayvenHawk 22 Junior Poster in Training

I'm working on an assignment and I need to swap the values from the left side of the tree to the right side and vise versa. I'm having no luck on it so far.

Here is the header file with the important areas

template<class elemType>
struct nodeType
{
   elemType	           info;
   nodeType<elemType>  *llink;
   nodeType<elemType>  *rlink;
};

template<class elemType>
void binaryTreeType<elemType>::swapSubtreeNodes(nodeType<elemType>* p)
{
   if (p==NULL) 
   {
      return;
   }
   else 
   {
      struct nodeType<elemType> *temp;
      // do the subtrees
      swapSubtreeNodes(node->left);
      swapSubtreeNodes(node->right);
      // swap the pointers in this node
      temp = node->left;
      node->left = node->right;
      node->right = temp;
   }
}

And here is my main menu

int main()
{

	binaryTreeSearch<int> tree;
	int num;

	cout << "My Binary Tree Swap Function Program!"<<endl;
	cout << endl;
	cout << "Insert your numbers (Press Enter after each number)."<<endl;
	cout << " To finish enter -999"<<endl;
	tree.insert(0);
	cin>>num;

	while(num != -999)
	{
		tree.insert(num);
		cin>>num;
	}

	cout << "Here is your unswapped Binary Tree."<<endl;
	tree.printTree();
	cout <<endl;
	cout <<endl;
	cout << "Here is your swapped Binary Tree."<<endl;
	[B]tree.swapSubtreeNodes();[/B] <----- This is where I'm stuck
	tree.printTree();
	cout << endl;

What am I not seeing here, other than the fact when I call the function I have no arguments in it.

RayvenHawk 22 Junior Poster in Training

i have an assignment I've completed except for copying a queue into another queue. According to the book the code for copying is almost the same for a stack, but when I tell my program that copy = original, it's blank. Here is the code I have so far.

BTW I know it's not 100% complete but that portion I haven't done is irrelevent to my problem.

header file

#include <iostream>
#include <cassert>

template<class Type>
class queueType
{
public:
	const queueType& operator=(const queueType<Type>&);
	void addQueue(const Type& queueElement);
	void deleteQueue();
	queueType(int queueSize = 100);
	queueType(const queueType<Type>& otherQueue);
	~queueType();

private:
	int maxQueueSize;
	int count;
	int queueFront;
	int queueRear;
	Type *list;
	void copyQueue(const queueType<Type>& otherQueue);
};

template<class Type>
void queueType<Type>::copyQueue(const queueType<Type>& otherQueue)
{
	delete [] list;
	maxQueueSize = otherQueue.maxQueueSize;
	queueFront = otherQueue.queueFront;
	queueRear = otherQueue.queueRear;
	list = new Type[maxQueueSize];
	assert (list != NULL);

	for(int j = 0; j < queueFront; j++)
		list[j] = otherQueue.list[j];
}

And here is my main program

cout << "How big do you want your queue to be?" << endl;
		cin >> size;

		queueType<int> intQ(size);
		queueType<int> copy(size);
		queueType<int> work(size);

		intQ.initializeQueue();

                                copy = intQ;
		work = intQ;


		if (select == 2)
		{
		copy = intQ;
		cout << "The Queue contains: ";
		while(!copy.isEmptyQueue())
		{
		cout<< copy.front() <<" ";
		copy.deleteQueue();
		}
                                }

I only posted the relevent code, so if you need anymore let me know.

Thanks

RayvenHawk 22 Junior Poster in Training

I've finished writing the program for my class and everything actually does what it's suppose to (well 99% anyway).

I'm going to add snippets of the code that should help figure out the small glitch. What's happening is I can add x amount of elements to my stack and display them, but when they are displayed they are in reverse order instead of from bottom to top (the order they were input into the stack).

template<class Type>
Type mystack<Type>::top() const
{
	assert(stackTop != 0);
	return list[stackTop - 1];
}

the above is the command to display the elements

template<class Type>
void mystack<Type>::push(const Type& newItem)
{
	if(!isFullStack())
	{
		list[stackTop] = newItem;
		stackTop++;
	}
	else
		cout <<"Cannot add to a full stack."<<endl;
}

the above is the code to push the new element into the stack

if (choice == 1)
		{
			do
			{
				cin >> num;
				intStack.push(num);
				j++;
			}
			while(j < amount);
			workStack = intStack;
		}

the above is the main function to call the push command. (int j is initialized to 0)

Any reason why my stack is displaying backwards??

mharie_chue commented: sir, how was the codes in reversing a word using stacks? +0
RayvenHawk 22 Junior Poster in Training

to add a function to an item on your form window it really depends on what function you need it to do. There are a few ways to get to that point.

1) As Lizr said on the form design windows (the screen you add the items to), you right click the item you want to add a function to and modify it's event.

2) Double click the item will allow you to work with the function, the drawback here is it automatically creates a "On_click" event, so unless you want that then this way is not the way to go.

3) Click the tab on top labeled Form1.cs (not sure what program you're using for C#, but I'm using VS2008 Pro)

RayvenHawk 22 Junior Poster in Training

But if I try to open the file with the in, out, and app parameters...

fstream openfile;
openfile("my_file.txt", fstream::in | fstream::out | fstream::app);
if(openfile.fail())
{
      cout<<"Error opening file.";
}
else
{
      mainprog();
}

... the program fails to open the file and displays the error message. Any suggestions?

On the openfile line, are you telling the compiler that it should check the following:

fstream::in (or) fstream::out (or) fstream::app???

if so you are short 1 | for each instance (an OR command is ||)..

if not, then completely disregard all the above and kind of explain what you're trying to accomplish on that line.

RayvenHawk 22 Junior Poster in Training

Ok I made the adjustments to the program so the list now builds itself forward instead of backwards. My only other issue is to sort the X values.

#include <iostream>
#include <algorithm>
#include "listnodes.h"

using namespace std;

listnodes::listnodes()
{
	//sets struct pointers to NULL
	p = NULL;
	g = NULL;
}

void listnodes::addx()
{
	//creates pointers for nodex x and asks for input for int num
	nodex *first, *newNode;
	int num;
	cout << "Enter a list of X values ending with -999." << endl;
	cin >> num;
	first = NULL;

	while (num != -999)
	{
		//stores values from int num into linked list (nodex)
		newNode = new nodex;
		newNode->x = num;
		newNode->next = NULL;

		//function to add values from beginning to end
		if (p == NULL)
		{
			p = first = newNode;
		}
		else
		{
			first->next = newNode;
			first = newNode;
		}
		cin >> num;
	}
}

void listnodes::addy()
{
	//creates pointers for nodes
	nodey *second, *newNode;
	int num;
	cout << "Enter a list of Y values ending with -999." << endl;
	cin >> num;
	second = NULL;

	while (num != -999)
	{
		//sets values from int num into linked list
		newNode = new nodey;
		newNode->y = num;
		newNode->Next = NULL;

		// function to add values from beginning to end
		if (g == NULL)
		{
			g = second = newNode;
		}
		else
		{
			second->Next = newNode;
			second = newNode;
		}
		cin >>num;
	}
}

void listnodes::displayx()
{
	//creates node pointer to print list out
	nodex *current;
	current = p; …
RayvenHawk 22 Junior Poster in Training

Ok I improved the code to seperate the functions and it works 99% of the intended purpose.

What I'm needing is to sort the X values and leave the Y values unsorted (which is already done). What I current have it just displays the first value I entered, removing the rest.

#include <iostream>
#include <algorithm>
#include "listnodes.h"

using namespace std;

listnodes::listnodes()
{
	p = NULL;
	g = NULL;
}

void listnodes::addx()
{
	nodex *first, *newNode, *sort;
	int num;
	cout << "enter a list of X values ending with -999." << endl;
	cin >> num;
	first = NULL;

	while (num != -999)
	{
		newNode = new nodex;
		newNode->x = num;
		newNode->next = first;
		first = newNode;
		cin >> num;
	}
	if (p == NULL) p = first;
}

void listnodes::addy()
{
	nodey *second, *newNode;
	int num;
	cout << "enter a list of X values ending with -999." << endl;
	cin >> num;
	second = NULL;

	while (num != -999)
	{
		newNode = new nodey;
		newNode->y = num;
		newNode->Next = second;
		second = newNode;
		cin >> num;
	}
		if (g == NULL) g = second;

}

void listnodes::displayx()
{
	nodex *current, *q, *r;
	for( q = p ; q->next != NULL ; q = q->next )
		{
			for( r = q->next ; r->next != NULL ; r = r->next )
				{
					if (r->x<q->x)
						{
							int temp;
							temp = r->x;
							r->x = q->x;
							q->x = temp;
						}
				}
		}

	current = q;
	cout << "Your X values are: ";
	while (current …
RayvenHawk 22 Junior Poster in Training

Ok nevermind I finally got it to display the values. Instead of trying to seperate each function and then execute them from main, I just threw them all into a single function and executed that from main. Now I have one last problem. It prints them out in reverse order. How would I print them out from 1st inputted to last inputted?

Here is my current working code:

#include <iostream>
#include "listnodes.h"

using namespace std;

listnodes::listnodes()
{
	p = NULL;
	g = NULL;
}

void listnodes::addx()
{
	nodex *first, *newNode;
	nodey *second, *Newnode;
	int num;
	int num2;
	cout << endl;
	cout << "Enter your X values, ending with -999." << endl << endl;
	cin >> num;
	first = NULL;

	while (num != -999)
	{
		newNode = new nodex;
		newNode->x = num;
		newNode->next = first;
		first = newNode;
		cin >> num;
	}
	cout <<endl;
	cout << "Enter your Y values, ending with -999." <<endl << endl;
	cin >> num2;
	second = NULL;

	while (num2 != -999)
	{
		Newnode = new nodey;
		Newnode->y = num2;
		Newnode->Next = second;
		second = Newnode;
		cin >> num2;
	}
	nodex *current;
	nodey *current2;
	current = first;
	current2 = second;
	cout << "The X values are: ";
	while (current != NULL)
	{
		cout <<current->x << " ";
		current = current->next;
	}
	cout << endl;
	cout << "The Y values are: ";
	while (current2 != NULL)
	{
		cout << current2->y << " ";
		current2 = current2->Next;
	}
	cout << endl;
}

Thanks a bunch, especially Salem, …

RayvenHawk 22 Junior Poster in Training

What are p and g in the constructor?

They are pointers for the nodex & nodey.

#include <iostream>

#ifndef LISTNODES_H
#define LISTNODES_H

using namespace std;

class listnodes
{
private:

	struct nodex
	{
		int x;
		nodex *next;
	}*p;

	struct nodey
	{
		int y;
		nodey *Next;
	}*g;

public:

	listnodes();
	int addx();
	int addy();
	void displayx();
	void displayy();

protected:
                nodex *first;
                nodey *second;
	
};
#endif

addx and addy seem to be doing the right thing, but they're only updating local variables.
Sure they build a list, but it is lost as soon as you return unless you store the head of the list in a class member variable.

How would I go about doing that? I tried using return first & return second, but it wont compile.

RayvenHawk 22 Junior Poster in Training

Ok here is my updated code, it won't compile but I can't find where exactly my error is in the code. When I click the error lines it doesnt bring anything up.

This is my source for the class file

#include <iostream>
#include "listnodes.h"

using namespace std;

listnodes::listnodes()
{
	p = NULL;
	g = NULL;
}

void listnodes::addx()
{
	nodex *first, *newNode;
	int num;
	cout << "enter a list of X values ending with -999." << endl;
	cin >> num;
	first = NULL;

	while (num != -999)
	{
		newNode = new nodex;
		newNode->x = num;
		newNode->next = first;

		first = newNode;
		cin >> num;
	}
}

void listnodes::addy()
{
	nodey *second, *newNode;
	int num;
	cout << "enter a list of X values ending with -999." << endl;
	cin >> num;
	second = NULL;

	while (num != -999)
	{
		newNode = new nodey;
		newNode->y = num;
		newNode->Next = second;

		second = newNode;
		cin >> num;
	}
}

void listnodes::displayx()
{
	nodex *current;
	current = first;
	while (current != NULL)
	{
		cout << "X-Value:" << current->x;
		current = current->next;
	}
}

void listnodes::displayy()
{
	nodey *Current;
	Current = second;
	while (Current != NULL)
	{
		cout << "Y-Value:" << Current->y;
		Current = Current->Next;
	}
}

Here is my main program

#include <iostream>
#include "listnodes.h"

using namespace std;

int main()
{

	listnodes ll;

	cout << " Welcome to my linked list program! " << endl;
	cout << " Enter your X value: ";
	ll.addx();
	cout << endl;
	cout << " Enter …
RayvenHawk 22 Junior Poster in Training

I'm having to create a program that uses a linked list to ask for X & Y points and stores them in a linked list and then displays those results.

My problem here is when it gives me the output I only see the last 2 entries I've made. It's not storing all the values I've inputted. I need a push in the right direction.

Thanks

#include <iostream>
#include <list>

using namespace std;

int main()
{
	struct node
	{	
		int x;
		int y;
		node *nxt;
	};
	node *start_ptr, *temp, *current;
	temp = new node;
	start_ptr = NULL;
	int numPoints = 0;
	int i = 0;

	cout << "Welcome to my Linked List Project" << endl;
	cout << endl;
	cout << "How many points do you wish to enter? ";
	cin >> numPoints;

	do
	{
		cout << "Enter a X value: ";
		cin >> temp->x;
		i++;
		cout << "Enter a Y value: ";
		cin >> temp->y;
		//temp->nxt = NULL;
		start_ptr = temp;
	}
	while (i < numPoints);
	current = start_ptr;
	while(current != NULL)
	{
		cout << "Here are your X values: " << current->x << " ";
		cout << endl;
		cout << "Here are your Y values: " << current->y << " ";
		cout << endl;
		current = current->nxt;
	}
}
RayvenHawk 22 Junior Poster in Training

Ok I went back to the drawing board a little bit and I believe I'm starting to see the light at the end of the tunnel. But now my problem is displaying the contents of the vector.

Here is my new code and at this point I assume it stores the data I input into the vector, but until I can have it output the contents I'm not positive.

#include <iostream>
#include <string>
#include <vector>
#include "student.h"

using namespace std;

int main()
{
	int numStudents = 0;
	int select;

	student mySTD;
	vector<student> std;
	
	cout << " Student scoring system! " << endl;
	cout << endl;
	cout << " Please make selection: " << endl;
	cout << " 1 - Add student " << endl;
	cout << " 2 - Get class average " << endl;
	cout << " 3 - Get high score " << endl;
	cin >> select;

	if (select==1)
	{
		mySTD.getData();
		std.push_back(mySTD);
		cout<<std
	}

	if (select==2)
	{
		cout << " Option 2 " << endl;
	}

	if (select==3)
	{
		cout << " Option 3 " << endl;
	}
}
RayvenHawk 22 Junior Poster in Training

Here is what I have so far for my class source file;

#include <iostream>
#include <vector>
#include <string>
#include "students.h"

using namespace std;

void students::getData()
{
	int numStudents = 0;
	string lname;
	string fname;
	int grade = 0;
	int i = 0;
	int avg = 0;
	int choice;
do
{
	cout << " Welcome to Student Records "<<endl;
                cout << " Please make selection "<<endl;
 	cout << " 1 - Add students "<<endl;
	cout << " 2 - Students below average "<<endl;
	cout << " 3 - Students with highest score "<<endl;
	cout << " 4 - Quit program "<<endl;
	cin >> choice;

	if (choice==1)
	{
		cout << " How many students do you wish to input? : ";
	cin >> numStudents;

	vector<getData> students;

	do
	{
		cout << " Student " << i+1 <<" last name: ";
		cin >> lname;
		students.push_back(lname);

		cout << " Student " << i+1 <<" first name: ";
		cin >> fname;
		students.push_back(fname);

		cout << " Student " << i+1 <<" test score: ";
		cin >> grade;
		students.push_back(grade);
		i++;
		avg = grade / numStudents;

	}
	while (i < numStudents);
	}
	
	if (choice==2)
	{
		cout << " The average score is: "<< avg <<endl;
	}

	if (choice==3)
	{
	}

	if (choice==4)
	{
		cout << " Now Exiting Program "<<endl;
	}
}
while (choice !=4);
}

my main source file just activates the getdata and the rest is run from the class file.

What I ultimatly want it to do is create a single vector that containes …

RayvenHawk 22 Junior Poster in Training

How about using a struct?

struct student
{
    string name;
    double score;
};

vector <student> students;

Or if a student can have more than one test score:

struct student
{
    string name;
    vector <double> scores;
    double average;
};

vector <student> students;

How would I put that in the class file so that I can call it from my main program file?

I do know structs are an alternative to classes, but I have to use at least 1 class in the program.

RayvenHawk 22 Junior Poster in Training

I have an assignment that asks to create a program to input students names & test scores. After which the user gets the option to calculate the average and print out which students were below, and/or print out the highest score and which students had that score.

Since the total # of students is unknown I'm using vectors in order to allow this. My problem at the moment is how to combine both char input and double input into a vector container and be able to generate the scores. I've already scrapped 3 different versions of my code since I hit a road block each time. I ideally want to create 2 classes (one for student names and the other for scores), but not sure how to bring those values from the class into the vector in the main program file.

Actually come to think of it, I can create a tmp1 for the name & tmp2 for the grade and add both to a container, but then I'm back at my original question on how to combine char with a integer (well double since scores may use decimals).

Any help would be greatly appreciated.

Thanks