sfuo 111 Practically a Master Poster

I compiled this with Code::Blocks and Visual Studio and both worked just fine.

sfuo 111 Practically a Master Poster

Based on what you posted you have just made your prototypes but you have not actually defined any of the functions.

sfuo 111 Practically a Master Poster

The issue lies within your function gasket().

On line 34 you are missing an equals sign between point and T, so it should look like

GLPoint point = T[index];

Then when you are adding point.x and t[index] then dividing by 2 you really want to add each component then divide by two. So line 42 and 43 should look like

point.x = (point.x + T[index].x) / 2;
point.y = (point.y + T[index].y) / 2;

Also I'm not sure about you but when I try to compile it gives me a bunch of undefined reference errors about all the OpenGL functions, so at the top I had to put

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
sfuo 111 Practically a Master Poster

It looks like all your errors/problems are in "cdrom.cpp".

In the function CDROM::setName() you have getline(cin, name) being printed out in your cout statement. The function getline() returns *this which is a pointer to the istream object being used (I think, either way this is not what you want). Also you have cin.ignore() being used which is pointless because getline() reads the '\n'. cin.ignore() should be used after reading in a number (int, float, double) because when reading in a number you only read in digits, decimals and signs (+/-), which results in characters typed in after to be left in the input buffer (ie "22char\n" results in "char\n" being left in the input buffer).

The next function, CDROM::setType(), has the exact same problem as CDROM::setName() so get rid of the cin.ignore() and do not output getline().

In CDROM::setCost() you want to clear the input buffer after you input the number because it leaves characters in the buffer, but you do this after you get the input not before. In order to use the line cin.ignore(numeric_limits<streamsize>::max(), '\n'); you need to include <limits> at the top because numeric_limits<streamsize>::max() is defined within it. If you do not clear the input buffer then when this loops for the next CDROM input you will not see text pop up until you type in something.

Here is what I did to correct the errors.

void CDROM::setName()
{
    cout << "Please enter name : ";
    getline(cin, name);
}

void CDROM::setType()
// …
sfuo 111 Practically a Master Poster

If you compile that code the 2nd one is wrong.

sfuo 111 Practically a Master Poster

Those are warnings and that is because you have no included <stdio.h>.

sfuo 111 Practically a Master Poster

Your function prototypes are different than your function definitions. In the prototypes you are expecting a pointer to a vector where in the definitions you are expecting the reference of that object.

sfuo 111 Practically a Master Poster

How are the phone numbers and names stored in the file? Can you give us a sample?

sfuo 111 Practically a Master Poster

It's not so much about we don't wanna give you the answer without you putting any thought into it, but the fact that you won't learn anything and you will probably be asking the same question around this time next year.

Give it a shot and there are people that will help guide you or fix up what you have to get it working (if there was effort put in by you and you are stuck).

sfuo 111 Practically a Master Poster

I tossed it into Visual Studio C++ and it gave me a bunch of errors saying that you cannot do

cout << "[" << curNode->name << "]";

So I changed the Print() function to return a string and use a stringstream to create that string.

within the class

string Print() //displays contents of the list
{
	Node<T> *curNode = first;
	stringstream strm;
	if( curNode == NULL )
		return "";
	while(curNode != NULL)
	{
		strm << "[" << curNode->name << "]";
		curNode = curNode->next;
		if( curNode != NULL )
			strm << " -> ";
	}
	return strm.str();
}

new main

int main()
{
	List<string> people;
	people.Add("John");
	people.Add("Stewart");
	people.Add("Hanna");
	cout << people.Print() << endl;
	people.AddAt("Patrica", 2);
	cout << people.Print() << endl;

	return 0;
}

EDIT: You also have to include <sstream> at the top

Is the error that you got a run-time error?

sfuo 111 Practically a Master Poster

Since it says there are no duplicate inputs I'm guessing (and there is no way to check) there will be no need for checking if a duplicate number was entered. You can throw on a check to restrain input from [0,n).

This is what I came up with "1 day ago" according to this thread.

#include <iostream>
using namespace std;

int main()
{
	int n = 10, inpt;

	for( int i = 0; i < n; i++ )
		cin >> inpt;

	for( int i = 0; i < n; i++ )
		cout << i << endl;

	return 0;
}
sfuo 111 Practically a Master Poster

I wrote this linked list a while ago. After reading yours for a bit I went back and modified mine to use templates and used your names.

You can take a look at this and use what you want.

It has four functions:
Add() which appends a node to the list
AddAt() which inserts a node at an index
AddAfter() which inserts a node after the named node
Print() displays the contents of the list

#include <iostream>
using namespace std;

template <typename T>
struct Node
{
	Node(){};
	Node( T n )
	{
		name = n;
		next = NULL;
	}
	T name;
	Node *next;
};

template <typename T>
class List
{
	Node<T> *first;

	public:

	List()
	{
		first = NULL;
	}

	void Add(T name) //adds a new entry to the list
	{
		Node<T> *newNode = new Node<T>(name);
		Node<T> *curNode = first;


		if( curNode == NULL )
		{
			first = newNode;
			return;
		}

		while(curNode->next != NULL)
		{
			curNode = curNode->next;
		}
		curNode->next = newNode;
	}

	void AddAt(T name, int index)
	{
		Node<T> *newNode = new Node<T>(name);
		Node<T> *curNode = first;
		Node<T> *nexNode = 0;
		Node<T> *prvNode = 0;

		if( curNode == NULL )
		{
			first = newNode;
			return;
		}

		int i = 1;
		while(curNode->next != NULL && i != index)
		{
			prvNode = curNode;
			curNode = curNode->next;
			i++;
		}

		if( i != index )
		{
			curNode->next = newNode;
			return;
		}

		if( prvNode == NULL )
		{
			nexNode = first;
			first = newNode;
			newNode->next = nexNode;
			return; …
Braindead90 commented: Gave a detailed explanation of suggestion even with comments inside code... Very Helpful +0
sfuo 111 Practically a Master Poster

Yeah but if you think about it a file is pretty much a big array of characters so if he would let you do that then thats a joke.

sfuo 111 Practically a Master Poster

You have to create a temporary holding variable since you cannot just write

num1 = num2;
num2 = num1;

since this will result in them both being equal to num1.

With the temporary variable there you store the original value of num1 then you change the value of num1 but you still hold its previous value in tmp. Then you can make num2 equal to tmp. All this does is swaps the two numbers.
This has to happen because below we assume that num1 is greater than num2, and if this isn't true then it will not work as intended (it will loop forever).

sfuo 111 Practically a Master Poster

It looks like you are using visual studio C++, correct? If so you have to be very careful what project type you use and your main() function entry point name. For a Win32 Console Application you have to use main() or _tmain(). If you make a Win32 Project then you have to use WinMain() or _tWinMain() but you cannot use main() or _tmain().

If you want to keep main() then you gotta make sure that you have the correct project type.

Also after compiling in VS C++ I got the same warnings for using strcpy() so sorry I said to change it but I would revert to strcpy_s() (for some reason code::blocks does not have that function or something even tho I included cstring and string.h and it throws no warnings).

sfuo 111 Practically a Master Poster

Do you have to use substr()? Because this can be easily done with a for() loop.

#include <iostream>
using namespace std;

int main()
{
	string str;
	bool palindrome = true;

	cout << "Please enter a sentence: ";
	getline(cin, str);

	for( int i = 0, j = (int)str.length()-1; (i < (int)str.length() && j >= 0 && i <= j); i++, j--)
	{
		if( str[i] != str[j] )
		{
			palindrome = false;
			break;
		}
	}

	if( palindrome )
		cout << str << " is a palindrome!" << endl;
	else
		cout << str << " is not a palindrome!" << endl;

	return 0;
}
sfuo 111 Practically a Master Poster

I commented the lines that I changed but I'll give the line numbers too.

Added lines 4, 5.
Modified lines 128, 129, 130.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib> //added
#include <cstring> //added

using namespace std;

const int MAXCHAR = 101;
const int CAP = 100;

struct Cart
{
	char itemName[MAXCHAR];
	char itemPrice[MAXCHAR];
	char itemTotal[MAXCHAR];
};

void menu();
char getCommand();
void exeCommand(Cart [], int &, char);
void addItem(Cart [], int &);
void showList(Cart [], int &);
void findCart(Cart [], int &);
void loadData(Cart [], int &);
void addItem(ifstream &, Cart [], int &);
void saveData(Cart [], int &);

int main(void)
{
	Cart shopping[CAP];
	int size = 0;
	char option;
	loadData(shopping, size);
	do
	{
		menu();
		option = getCommand();
		exeCommand(shopping, size, option);
	}while(tolower(option) != 'q');
}

void menu()
{
	cout << "Welcome to Smart Shopping Cart! :\n"
	<< "(a) to add an item\n"
	<< "(s) to show the items list\n"
	<< "(f) to find an item by item name\n"
	<< "(q) to quit\n";
	cout << "Please enter an option: ";
}

char getCommand()
{
	char ans;
	cin.get(ans);
	switch (tolower(ans))
	{
		case 'a':
		case 's':
		case 'f':
		case 'q':
			cin.ignore(100, '\n');
			return ans;
		default:
			cout << "Illegal input.";
			cin.clear();
			cin.ignore(100, '\n');
			system("cls");
			menu();
			return getCommand();
	}

}

void exeCommand(Cart list[], int &size, char ans)
{
	switch(tolower(ans))
	{
		case 'a':
			addItem(list, size);
			saveData(list, size);
			break;
		case 's':
			showList(list, size);
			break;
		case 'f':
			findCart(list, size);
			break;
		case 'q':
			cout << "Thanks for using Smart Shopping Cart. Goodbye!" << endl;
			return; …
sfuo 111 Practically a Master Poster

I don't see how it doesn't work if you input num1 larger than num2.

sfuo 111 Practically a Master Poster

This compiled fine for me other than the fact I had to include cstdlib (for system()) and cstring (for strcmp() and strcpy()) and I had to change strcpy_s() to strcpy().

sfuo 111 Practically a Master Poster

I would use two for() loops. You can use a while() loop but I tend to avoid them when you want to count through a range of values.

#include <iostream>
using namespace std;

int main()
{
	int num1, num2;

	cout << "Enter a positive integer: " << endl;
	cin >> num1;
	cout << "Enter another positive integer: " << endl;
	cin >> num2;

	if( num1 > num2 )
	{
		int tmp = num1;
		num1 = num2;
		num2 = tmp;
	}

	//low to high
	for( int i = num1; i <= num2; i++ )
		cout << i << " ";
	cout << endl;

	//high to low
	for( int i = num2; i >= num1; i-- )
		cout << i << " ";
	cout << endl;

	return 0;
}

I didn't throw in any checking for the two inputs.

sfuo 111 Practically a Master Poster

When you put #included <cmath> (notice they are < brackets not " quotes) you got a bunch of errors. If you read the errors they just say that it doesn't know what datatype you are trying to pass into the ToString() function. The work around to for this is to cast the result into a double or something (I tried long double and it didnt work).

So just change the last line of your calcu_Click() function to

this->rp->Text=Convert::ToString((double)pow(ni,nii));

Edit: make sure you include cmath at the top of Form1.h but under the #pragma once

sfuo 111 Practically a Master Poster

You would need to read the input in as a string then parse the string and store each part into variables.

If '.' was always your word separator then you could use the find and substring functions that are part of the string class.

Here is an example of this.

#include <iostream>
using namespace std;

int main()
{
	char dot = '.';
	string str = "", word1 = "", word2 = "";
	getline(cin, str); //takes in the whole line (this reads in all spaces up to a newline character '\n'

	word1 = str.substr(0, str.find(dot)); //creates a substring from the start of the string up to the dot
	word2 = str.substr(str.find(dot)+1, str.length()); //creates a substring from the dot to the end of the string

	//outputs each word
	cout << word1 << endl;
	cout << word2 << endl;

	return 0;
}
sfuo 111 Practically a Master Poster

That is because cin is looking for a whitespace between each input(' ' or '\n'). So if you typed "much . love" it would work the way you have it set up now, but if you typed "much.love" then sztext1 would be "much.love" and it doesn't show Works... because it is waiting for input of dot and sztext2.

sfuo 111 Practically a Master Poster

Honestly I'd have to see some source code before I can tell you how to fix it. The code that I have from the default VC++ template is really bare bone.

So if you could zip up your project files (do not need all the .obj files and other stuff that is made when compiling) and I'll take a look at it.

sfuo 111 Practically a Master Poster

One huge problem that you had was that you were not allocating memory for your stack. The reason why you did not get run-time errors for this is because you were never actually using your stack, which is why (along with a few other things) you were getting garbage values for the initial test.

Within the oper() function you have a check that attempts to see if there are at least two numbers in the stack and in your case that is never true so it just returns. I would suggest you remove that all together and take advantage of the fact that your pop() functions return a bool.

Out of all the functions you have the only one that is correct is the pop() function. Your push() function is changing the memory address of mPtop when what you really want is to change the value at mPtop's memory address, and you need a range restriction on that function so you are not pushing too many values onto a stack of a limited size (otherwise you go out of bounds of the memory allocated and this results in a run-time error).

For the oper() function your division function is wrong and you need to look up how to divide complex numbers (I just typed in dividing complex numbers into google) and attempt to come up with the same result that I put below (I did it all with variables on pen and paper and then transferred it …

sfuo 111 Practically a Master Poster

Can you post all the code? You just posted up the Calculator source file and are missing the myComplex class all together and the main function.

sfuo 111 Practically a Master Poster

I have never made a Windows Form Application before but I just made one out of the template and threw #include <cmath> (you should use cmath not math.h in C++) at the top and it compiled without a problem, since as I suspected just C++ with a big library attached to it.

So what you can do is just go to the source file with all the functions you are trying to use the cmath functions in and include cmath at the top of it.

sfuo 111 Practically a Master Poster

Everything has a datatype. In this case ofstream is the datatype and myfile is the instance of it. Just because it is not a basic datatype (ie int, float, char..) does not mean it is not a type. Obviously a stream type is a lot more complicated than other objects since it interacts with user input/output but for the most part objects are just made up of a bunch of basic datatypes.

Here is an example of declaring and using ofstream within the function.

#include <iostream>
#include <fstream>
using namespace std;

void displayResults()
{
	ofstream myfile("payrecord.txt");

	myfile << "Fst Name" << endl;

	myfile.close();
}

int main()
{
	displayResults();


	return 0;
}
sfuo 111 Practically a Master Poster

This is one of the most basic examples I can come up with that includes exactly what you asked.

#include <iostream>
using namespace std;

class ClassA
{
	int a, b;

	public:
	ClassA(){}; //need a default constructor
	ClassA(int _a, int _b)
	{
		a = _a;
		b = _b;
	}
};

class ClassB
{
	int x, y, z;
	ClassA a1;

	public:
	ClassB(){}; //not needed in this but should have one
	ClassB(int _x, int _y, ClassA _a1, int _z)
	{
		x = _x;
		y = _y;
		a1 = _a1;
		z = _z;
	}
};

int main()
{
	ClassA A(1, 2);
	ClassB B(4, 5, A, 6);


	return 0;
}
sfuo 111 Practically a Master Poster

Your function displayResults() has no idea that myfile exists.

There are a few things you can do. You can declare ofstream myfile as global, pass it through the function as a parameter or declare it within the function. If you are not writing to the file anywhere else but within displayResults() I would recommend creating myfile in there.

sfuo 111 Practically a Master Poster

fstream is part of the std namespace. So either put using namespace std; or

using std::fstream;

along with others that you need to use.

sfuo 111 Practically a Master Poster

This sounds like a trick question to me because if n was 50 or something and I gave the input 20, 30, 21, 49, 1, 35, ... 0 how would you be able to sort that without having a variable for each input.

To "sort" a bunch of input in ascending order with n numbers and no duplicates can be done by using a for() loop

for( int i = 0; i < n; i++ )
	cout << i << endl;
sfuo 111 Practically a Master Poster

Yep. Unless you are on windows then you can use system("PAUSE"); but thats kind of frowned upon.

sfuo 111 Practically a Master Poster

return 0 has nothing to do with pausing the program, its just a value that gets returned to the program that called it (since main is just a function that returns an int).

sfuo 111 Practically a Master Poster

You can't. If your compiler supports it then you can have a pause when it is ran through the compiler but no program runs and pauses at the end without being forced to.

sfuo 111 Practically a Master Poster

One big thing you have to understand is that a function (ie main()) is not a class.

Classes hold variables and functions which can be accessed/used via the "dot" (.) operator.

Here is an example of an Event_Time class that prints out the current date and time when you call the function CurrentTime().

#include <iostream>
#include <ctime>

using namespace std;

class Event_Time
{
	time_t current_seconds;
	tm *timeinfo;
	char buffer[80];

	public:

	void CurrentTime()
	{
		current_seconds = time(NULL);
		timeinfo = localtime(&current_seconds);
		strftime( buffer, 80, "Event Date: %x", timeinfo );
		cout << buffer << endl;
		strftime( buffer, 80, "Event Time: %X %Z", timeinfo );
		cout << buffer << endl;
	}
};

int main()
{
	Event_Time event; //creates a new event

	event.CurrentTime(); //displays the current time

	return 0;
}

Notice how there is no assignment done outside of functions within the class (if you want to declare and initialize at the same time outside of functions within the class then it must be a static constant variable (ie static const int x = 5 ).

If you want to initialize variables right when the object is made then you either call a function that assigns or you define a constructor for the class.

Here is an example using a constructor.

#include <iostream>

using namespace std;

class myClass
{
	int myVariable;


	public:

	myClass() //Constructor. Notice that it does not have a return type. This will replace the default constructor.
	{
		myVariable = 5;
	}

	myClass( int in ) //This …
sfuo 111 Practically a Master Poster

After going through this it is clear that you do not understand a few things.

#1 you have to name your arguments/parameters for your functions (except for the function proto-types)
#2 you are using uninitialized variables in calculations (this is why you are getting 0)
#3 you are not passing the right variables into your functions and you are not using the passed variables within your function

Even if you did pass the correct variables in and there were no other problems, your formula for calculating the union fees and government taxes is incorrect (it should be gross*taxrate).

I have attached a revised copy that you should compare side by side with your original. The primary changes are where you call your calculation functions and your function definitions.

Edit: You should take a look at this page on functions.

sfuo 111 Practically a Master Poster

To display the value of X you need to put

cout << X << endl;

after X is calculated.

sfuo 111 Practically a Master Poster

I don't see the point in him posting that at all then. He is just showing someone, that doesn't know what they are doing, code that doesn't work.

@Adam Ma
I would highly recommend you go over this tutoral. I learned C++ from here and I use the reference section all the time.

sfuo 111 Practically a Master Poster

This took a bit more than 30 secs but it isn't full of errors and uses whitespace so you can actually see what is going on.

#include <iostream>

using namespace std;

int main()
{
	int num;

	cout << "please enter a number" << endl;
	cin >> num;
	if( num > 0 )
	{
		for( int i = 0; i < i; i++ )
		{
			cout << i << endl;
		}
	}
	else
	{
		cout << "number is less than or equal to 0" << endl;
	}

	return 0;
}
sfuo 111 Practically a Master Poster

You can try running what I have zipped up but my last guess as to what might be wrong is the fact that you have msvcrtd.lib and mfcs80ud.lib in 'Ignore Specific Default Libraries'. When I put those in I got errors but not the same ones as you.

sfuo 111 Practically a Master Poster

See attached image

The file that was inside the zip doesn't do anything. I removed all my linked libraries and tested to see what ones I need and don't need and there are three that you need in order to compile the code you posted.

kernel32.lib
user32.lib
gdi32.lib

You can check the box 'Inherit from parent or project defaults' to load in all the libraries in the lower section of the pop up box of the screen shot below.

sfuo 111 Practically a Master Poster

If you could zip it and post it here (with manage attachments) then I could open it and see what is wrong.

sfuo 111 Practically a Master Poster

I copied your source code and it runs fine after taking the semi-colons out.

Can you zip up the source files and the .sln, .vcxproj files? It should only be a few KB in size.

sfuo 111 Practically a Master Poster

You have a problem with the CreateWindowEx() function because your #define statements at the top have semi-colons at the end of them, and they are not supposed to have that. The preprocessor takes your defines and pretty much uses find-replace on your code then processes it. So your CreateWindowEx() would look like

hWnd = CreateWindowEx(NULL, L"WindowClass1", L"Input Test", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640;, 480;, NULL, NULL, hInstance, NULL);

Notice the ';'s that aren't supposed to be there.

Might be because you do not have the right libraries linked or your settings under 'Project > "ProjectName" Properties... > Configuration Properties > Linker > System > SubSystem' might be set to 'Console' rather than 'Windows'.

sfuo 111 Practically a Master Poster

You will have to show a lot more source code than that if you want a real answer.

What type is WINDOW_TITLE? All of those syntax errors could be caused by anything, especially after looking at how you were trying to assign an array from before.

sfuo 111 Practically a Master Poster

If I had to guess I'd say that you haven't linked any libraries to your project and when you fixed that one error it found even more, so it didn't break your program it just showed you the other bunch of errors you have.

To link the libraries to your project go to 'Project > "ProjectName" Properties...', expand 'Configuration Properties', expand 'Linker' and select 'Input'. Under 'Additional Dependencies' you should have nothing but you need some of the default windows ones in order to use the functions above. By default if you make a Win32 console or window project you should have 'kernel32.lib, user32.lib, gdi32.lib, winspool.lib, comdlg32.lib, advapi32.lib, shell32.lib, ole32.lib, oleaut32.lib, uuid.lib, odbc32.lib, odbccp32.lib', however you should only need the first three listed to operate.

The above libs are for the Windows functions, so you will need to add the ones for DirectX (which I do not know what ones you need since I use OpenGL) and whatever other libraries you are using.

You can also add more search directories for the libraries so you do not need to place them all in the Visual Studio lib folder. This is done by selecting 'General' instead of 'Input' and then selecting 'Additional Library Directories' where you just input the path of the folder containing the lib files you want to use.

sfuo 111 Practically a Master Poster

I'm not 100% sure why you are making a 100 element array to hold 24 indices. Also you are trying to treat an array like a function or something, but it is incorrect.

There are a few ways of doing this but here is the way I think you would want it

short indices[] =
{
        0,1,2,
        2,1,3,
        4,5,6,
        6,5,7,
        8,9,10,
        10,9,11,
        12,13,14,
        14,13,15
};
sfuo 111 Practically a Master Poster

From what I read on the Visual Studio Wiki there should be no major limitations by using the Express edition opposed to Ultimate or something you would pay for.

There are a few things in Visual C++ that I found annoying like the pre-compiled headers but most of that can be modified in the 'Project > "projectname" Properties...' section.

sfuo 111 Practically a Master Poster

The issue is because the value of _WIN32_WINNT is below 0x0501. When I compile in Code::Blocks I get the same problem, but if I compile in Visual Studio C++ then I no longer have the problem. This is because the version of MinGW that comes with Code::Blocks is giving _WIN32_WINNT me a value of 0x0400 whereas Visual Studio is giving me 0x0601.

The solution to this is to manually define WINVER and _WIN32_WINNT to 0x0601, install the latest version of MinGW (manually, because I tried the automatic installer and it didn't seem to do anything) or convert to the darkside and use Visual Studio.

If you are going to do some game development (I am assuming you are because you are playing around with DirectX) I would suggest using Visual Studio because I have ran into many problems trying to get stuff working with MinGW (NVIDIA PhysX SDK couldn't find lots of stuff).