sfuo 111 Practically a Master Poster

Lets see your main.cpp file and the rest of what you have because I'm pretty sure you are not declaring "beam" correctly.

sfuo 111 Practically a Master Poster

Add this line of code into your "counter.pp" file

int Counter::nCounters = 0;
sfuo 111 Practically a Master Poster

I see you just took the allinone.cpp if you actually want to learn some form of structure for coding bigger projects I suggest you look at the divided files and then look at the single. I find looking at something with 500+ lines a little overwhelming when you are just starting out.

sfuo 111 Practically a Master Poster

I have helped you out by writing what I think you want and put it into a "cleaner" format (could be more clean) and divided it into seperate files for structure. (file allinone.cpp is the whole thing in one file if this is for school and they want it in one)

I did my best to comment lines to show you what is going on.

I attached all the files.

sfuo 111 Practically a Master Poster

In the code I posted I tested what you wanted and it worked.

sfuo 111 Practically a Master Poster

twomers beat me to it but yes that is an easy fix for it.

sfuo 111 Practically a Master Poster

This is what I would do.

#include <iostream>
#include <string>

using namespace std;

int main()
{
	int myInt;
	string myString;
	
	cin >> myInt;
	cin.ignore(); //use this it ignores the last '\n' character
	getline(cin, myString);
	
	system("PAUSE");
	return 0;
}
sfuo 111 Practically a Master Poster

I wrote something for this and if you want to put in more numbers its really easy (not as easy if you would just use arrays) if you read the code and see what I'm doing.

#include <iostream>

using namespace std;

int main()
{
	int n1, n2, n3, n4, n5, a, b;
	
	cout << "input n1: ";
	cin >> n1;
	cout << "input n2: ";
	cin >> n2;
	cout << "input n3: ";
	cin >> n3;
	cout << "input n4: ";
	cin >> n4;
	cout << "input n5: ";
	cin >> n5;
	
	for( int i = 1; i <= 5; i++ )
	{
		switch(i)
		{
			case 1:
				a = n1;
				break;
			case 2:
				a = n2;
				break;
			case 3:
				a = n3;
				break;
			case 4:
				a = n4;
				break;
			case 5:
				a = n5;
				break;
		}
		for( int c = 1; c <= 5; c++ )
		{
			switch(c)
			{
				case 1:
					b = n1;
					break;
				case 2:
					b = n2;
					break;
				case 3:
					b = n3;
					break;
				case 4:
					b = n4;
					break;
				case 5:
					b = n5;
					break;
			}
			if( b > a )
			{
				int temp = a;
				a = b;
				b = temp;
			}
			
			switch(i)
			{
				case 1:
					n1 = a;
					break;
				case 2:
					n2 = a;
					break;
				case 3:
					n3 = a;
					break;
				case 4:
					n4 = a;
					break;
				case 5:
					n5 = a;
					break;
			}
			
			switch(c)
			{
				case 1:
					n1 = b;
					break;
				case 2:
					n2 = b;
					break;
				case 3:
					n3 = b;
					break;
				case 4:
					n4 = b;
					break;
				case 5:
					n5 = b;
					break;
			}

		}
		
	}
	
	cout << n1 << " " << n2 << " " << n3 << " " << n4 << " " << n5 << endl;
	
	system("PAUSE");
	return 0;
}
sfuo 111 Practically a Master Poster

I fixed up the code so it runs and threw in a few comments.

As GrnXtrm said you have a bunch of errors that mainly has to do with learning the format of a program. I hope my fix up/comments help.

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

//prototypes
//I changed your getInfo prototype because it was different from the one below
void getInfo(double &spools, double &stock, double &charges); //pass by reference so we do not need to make global variables
void display(double spools, double stock, double charges);

int main()
{
	double spools, stock, charges; //declare local vaiables
	
	getInfo(spools, stock, charges); //sets the variables based on user input
	display(spools, stock, charges); //displays information
	
	system("PAUSE");
	return 0;
}

//declare function outside of other functions(main)

void getInfo(double &spools, double &stock, double &charges)
{
	charges = 0; //sets special charges to 0 (not sure how you really want this done)
	char snh; //
	double chargesSet; //variable for special charges to be added to charges

	cout << "Enter the amount of spools ordered: ";
	cin >> spools;

	while(spools < 1)
	{
		cout << "Enter a number greater than 0: ";
		cin >> spools;
	}
	//you had return here which would stop the function from going any further

	cout << "Enter the amount of spools in stock: ";
	cin >> stock;

	while(stock < 0)
	{
		cout << "Enter a number greater than 0: ";
		cin >> stock;
	}
	//you had return here which would stop the function from going any further
	
	cout << …
sfuo 111 Practically a Master Poster

Sorry for the late reply.

#include <windows.h>

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)
{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
    	return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
    	0,                   /* Extended possibilites for variation */
    	szClassName,         /* Classname */
        "Windows App",       /* Title Text */
		WS_OVERLAPPEDWINDOW, /* default window */
        CW_USEDEFAULT,       /* Windows decides the position */
        CW_USEDEFAULT,       /* where the window ends up on the screen */
        544, …
sfuo 111 Practically a Master Poster

I went over this code with the default windows app code generated by dev C++ and I just see lots of errors.

For example:
Line 18: WINCLASSEX ex;
should be WNDCLASSEX ex;

Line 44: ShowWindow(handleWin, SM_SHOW);
should be ShowWindow(handleWin, nshowcmd);

Those are just a few if you want the template I have just ask and I'll post it since it isnt that long.

sfuo 111 Practically a Master Poster

Is this the output you want or that you are just getting? I removed the return that you were having problems with and it matchs those outputs.

sfuo 111 Practically a Master Poster

Post your whole code and I'll try to get it working.

sfuo 111 Practically a Master Poster

From just looking at the code I would say yes that return is the problem because it tells the function to return (do not run anything past this point) before it can recall itself. Other than that I think the code is fine.

sfuo 111 Practically a Master Poster

For this I would make 3 int vectors: input1, input2, output.

Make a function that reads in a file name and saves it to the vector. void fileToVector(string fileName, vector<int> &in); You would call this twice (once for each file) and then call a function that sorts them into one vector. void mergVectors(vector<int> v1, vector<int> v2, vector<int> &out); Try this out and see where you get with this I would post the whole code but you didn't post any code showing where you are at.

sfuo 111 Practically a Master Poster

You need it to be a constant string so try this.

system(("sendmail -options" + EMAIL_TEXT).c_str());

c_str() converts the string into a const char*.

sfuo 111 Practically a Master Poster

I modified your code so that it works the way that you want and changed some of your formatting so it is a bit easier to read.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
	int game[20][5]; //changed to [20][5] for your total

	for( int g = 0; g < 20; g++ )
		for( int q = 0; q < 5; q++ )
			game[g][q] = 0;
			
	srand((unsigned)time(0));
	
	int randomInteger, g;
	
	cout << "Enter the number of game you wish to update: Game #";
	cin >> g;
	if( g != 0 )
	{
		for( int q = 0; q < 4; q++ ) //you had it so it was just asking for numbers and not doing anything
		{
			randomInteger = rand() % 33; //each quarter is randomly made
			game[g-1][q] = randomInteger;
			game[g-1][4] += game[g-1][q]; //for your total
		}
	}
	while( g != 0 )
	{
		cout << "Do you wish to enter another game to update? If not, enter 0. Game#";
		cin >> g;
		if( g == 0 )
			break;
		for( int q = 0; q < 5; q++ ) //same as above
		{
			randomInteger = rand() % 33;
			game[g-1][q] = randomInteger;
			game[g-1][4] += game[g-1][q];
		}
	}
	
	cout << "Quarter 1	" << "Quarter 2	" << "Quarter 3	" << "Quarter 4       " << "Total" << endl;
	for( int j = 0; j < 20; j++ ) //outputs each quarter and total for each game
		for( int i = 0; i < 5; i++ ) …
sfuo 111 Practically a Master Poster

First off you want to call srand() before you use rand() otherwise you will always get the same value for the first random.

Also you can take a look at a snippet I made for allocating memory in a 2 dimensional array. It uses user input and it expands on every input but you only need it once. here.

Or you can just random the 2 numbers (x, y) and after that random you can declare the multidimensional array and then make your for() loop and fill it with random 1s and 0s.

Your random is assigning x and y both the same value (1 or 0). This could result in the array being [0][0]. For making random number you can use this formula num = (rand() % max+1-min) + min; for the size of your array. Then use rand() % 2; for your assignment for each value.

If this doesn't help just ask and I'll write you a quick example for what you need.

sfuo 111 Practically a Master Poster

That is exactly what you have.
If xxx was a pointer to getText() then you would have a problem.

sfuo 111 Practically a Master Poster

I could see there being a problem if you made xxx a pointer to getText() and some how getText() got destroyed then it would be pointing to an object that no longer exists.

The example you posted is assigning xxx to the value your getText() function returns. So xxx is equal to "Hello World!" and is not equal to getText().

sfuo 111 Practically a Master Poster

I didn't actually test with your code but nan means not a number. Give me a few min to copy your code and test it out.

sfuo 111 Practically a Master Poster

Your prototype functions need to match your full functions below main() unless you are trying to overload the functions (I don't think you are).
Also the timeoffall value that you get out of the function stays in the function because you aren't passing a variable by reference or making it so your function has a return value.

I would change your prototypes to:

double timeoffall(double);
void velatimpact(double);

And then in your main() you can go:

velatimpact(timeoffall(h));

or split it up by making a variable store the value of timeoffall() and passing that into velatimpact().

And your timeoffall() function should be changed to something like this:

double timeoffall(double h)
{	
	double timeoffall;
	timeoffall = sqrt (h/4.9);
	cout << "the ball was in the air for " << timeoffall << "seconds" <<endl;
	return timeoffall;
}
Trini89 commented: Very Helpful, advice worked wonderfully +2
sfuo 111 Practically a Master Poster

Why can't you just use char for sign like you are and if that is x then stop and for input and total I would just use integers.

#include <iostream>

using namespace std;

int main()
{
	char sign;
	bool end = false;
	int total = 0, input;
	
	cout << "Current total is: " << total << endl;
	do
	{
		cout << "Enter an operator ( + - * / or 'x' to quit ): ";
		cin >> sign;
		if( sign == 'x' || sign == 'X' )
		{
			end = true;
		}
		else if( sign == '+' )
		{
			cout << "Enter a number: ";
			cin >> input;
			total += input;
		}
		else if( sign == '-' )
		{
			cout << "Enter a number: ";
			cin >> input;
			total -= input;
		}
		else if( sign == '*' )
		{
			cout << "Enter a number: ";
			cin >> input;
			total *= input;
		}
		else if( sign == '/' )
		{
			cout << "Enter a number: ";
			cin >> input;
			if( input == 0 )
			{
				cout << "Cannot divide by zero!" << endl;
			}
			else
			{
				total /= input;
			}
		}
		else
		{
			cout << "Invalid operator!" << endl;
		}
		cout << "Total is: " << total << endl;
	}while( !end );
	
	system("PAUSE");
	return 0;
}
sfuo 111 Practically a Master Poster

Another way to write this would be:

class Fraction
{
	int numerator;
	int denominator;
	char sign;
	public:
	Fraction(int _num = 0, int _den = 1, char _sign = 'p');
};

Fraction::Fraction(int _num, int _den, char _sign)
{
	numerator = _num;
	denominator = _den;
	sign = _sign;
}
Fraction(int _num = 0, int _den = 1, char _sign = 'p');

Having the '=' operator in the first declaration of the function makes it so if you do not give that parameter a value it will use the value stated as the default.

sfuo 111 Practically a Master Poster

I knew you would say that because that is number 2 in your list of important things. lol

sfuo 111 Practically a Master Poster

I made some changes and added some comments, if I missed anything just ask.

I used one file instead of two just because I think its easier to just post small programs in one file but in larger programs I use lots of headers and source files.

#include <iostream>
//#include "MyFloat.h"
//Normally you use headers instead of source files for includes ( atleast from what I've seen)
using namespace std;



//MyFloat.h
class MyFloat
{
	//classes start off private so you do not need to put private: in unless you declare public: first
		//#define MAX_DIGITS 20
		const int MAX_DIGITS = 20;
		//enum {MAX_DIGITS = 20};  I would define this with #define or you can make it a const int within your class
		int Number[MAX_DIGITS]; //start at index 0 and dont add one to max
		int NumberOfDigits;  //use ints so you do not have to put int(Number[i]) in write
	public:
		void Write();
		friend void AssignValue(MyFloat& X);
};

void MyFloat::Write( )
{  
	if(!NumberOfDigits == 0)
	{   
		cout << "0.";
	    for(int i = 0; i < NumberOfDigits; i++) //if you start at i = 0 then dont add 1 to number of digits
		   cout << Number[i]; //remove int if you use int type for your Number[] array
	}
	else
		cout << "0.?";
}

//main.cpp
void AssignValue(MyFloat& X)
{
	X.Number[0] = 1;  //arrays start at index 0
	X.Number[1] = 2;
	X.Number[2] = 3;          // run program first this way with
	X.NumberOfDigits = 3;     // these numbers then change
}                         	  // X.NumberofDigits = 0, …
sfuo 111 Practically a Master Poster

As a general note if you want people to read your code learn to format it in a clean way. Having bad indents and no white space and cramming everything onto one line by throwing in semi-colons makes it just as hard to read if you don't use code tags and in the end when you compile this cutting out lines just makes it harder for you to go back to and fix up and will not make your file size any smaller.

I commented a few lines telling you what I did.

#include "stdafx.h"
#include <string>
#include <iostream>

using namespace std;

class vowels
{
	string input;
	int a, e, i, o, u, y;
	public:
	vowels();
	void getdata();
	void processdata();
	void display();
};
vowels::vowels()
{
	a = 0, e = 0, i = 0, o = 0, u = 0, y = 0; //made is so you dont redeclare the variables
	input = " ";
	getdata(); //when you make the variable class it auto starts the input instead of calling this function in main
}

void vowels::getdata()
{
	cout << "Enter String of Characters->> ";
	getline(cin,input);
	processdata(); //after input the vowel checker starts
	display(); //after vowel checker displays the data
}

void vowels::processdata()
{
	for( int x = 0; x < input.length()-1; x++ ) //added a for() loop for checking the string char by char not comparing the whole string
	{
		if( input[x] == 'A' || input[x] == 'a' ) //checks index 'x' and compares to a char …
jamdownian commented: Pure genius... +1
sfuo 111 Practically a Master Poster

Yeah like Grn Xtrm's edit says put in prompts before you ask for input because when I ran it the 1st time I didn't know what I was inputting for.

Also I would declare slash right at the start

char slash = '/';

instead of asking the user to put that in that just seems like an unnecessary input that could lead to an input error.

sfuo 111 Practically a Master Poster

On line 30 you have if( denom = 0 ) and it should be if( denom == 0 ) it crashes because it makes denom equal to zero and it is doing what you are trying to prevent.

sfuo 111 Practically a Master Poster

Attach your whole code so I can try running it and see what is going on.

sfuo 111 Practically a Master Poster

No problem. Good luck with the homework.

sfuo 111 Practically a Master Poster

I was able to get the same error as you by deleting the "player.cpp" file making it so only the prototype exists.

The only thing I can think of is is the "player.cpp" file part of the project? Sounds stupid but that would give you the error.

sfuo 111 Practically a Master Poster

Yeah and I use dev C++ too.

Trying hitting the rebuild all button it normally fixes lots of errors for me after I change a lots of code.

Also I see that you are using spaces to indent your code go Tools >> Editor Options and check Use Tab Character.

This makes it a lot cleaner and you just have to hit tab and it gives you a perfect indent.

sfuo 111 Practically a Master Poster

I copied exactly what you have and I didn't get any errors.

What compiler do you use?

sfuo 111 Practically a Master Poster

I use devC++ and if I want to use the <cstring> library I do not need to use <iostream> or <iostream.h>. And I have never used MFC so I wouldn't know but since I don't use it you do not need to include it.

Frederick2 commented: thanks, you're right! +2
sfuo 111 Practically a Master Poster

You have one of your cin's with operators going the wrong way << you want it >> like the rest of them.

Also, you have it so it compares the input to a variable that are not assigned. Either assign Apples, Oranges, Pears or change your if() statements to

if (fruit == "Apples")
if (fruit == "Oranges")
if (fruit == "Pears")

And I take it you are going to fix up the type because I could type anything in and it would say
You have selected "input" Apples.

sfuo 111 Practically a Master Poster

The function mazeTraverse() is pretty much this whole program. It checks to see if the position in the maze that is it at is a space and then if it is it runs its self 4 items (up one spot, down one, left one, right one) and doing the same checks as before and if those spots are spaces then it runs its self another 4 times. This happens until it comes to a dead end.

Not sure if that helps it took me a few secs to look at the function to figure out what it was doing.

xxunknown321 commented: thank you +0
sfuo 111 Practically a Master Poster

This confused me too but I went to http://www.cplusplus.com/reference/clibrary/cstring/ and looked up a cstring function that would work for this.

if( strcmp(input, "Synergy") != 0 ) return;

Returns 0 if they are equal.

sfuo 111 Practically a Master Poster

Try the function atoi() it is not used by all compilers but you can see if it works. Or take the value in as an int and use itoa() for adding the number to the end of the string.
(itoa() converts int to string and atoi() is string to int)

sfuo 111 Practically a Master Poster

I'm not 100% sure how you want to set up all your variables and parameters but here are a few things:
Use a character array (char var[]) for a parameter char* string.
For a const char* parameter and you want to use a c++ string then convert the string with .c_str() making it a const char* array.

You could make it work either way but you have to pick one and stick to it otherwise you are adding in lines of code to convert from one to another. Personally I would stick to C++ strings for this.

sfuo 111 Practically a Master Poster

I would take testpid in as a string or convert it to one and put

pKeyboardHelper = new CKeyboardHelper(("WindowerMMFKeyboardHandler_"+testpid).c_str());

This should work if not I'll look at another way.

sfuo 111 Practically a Master Poster

By the looks of it you want to be working with cstrings instead of the "new" C++ strings.

#include <cstring>
int main(){
	char input[100];
	cin.getline(input,100);
	return 0;
}

With this you take in a char array from getline() instead of a string and are able to pass it through your function SendText.

Or you can fix it without changing as much code by making it so SendText() takes in a UINT and string for parameters.

And for both you would remove the .c_str() attribute from input.

(I see you have std::cin, std::hex but you do not have std::string or std::cout meaning you are using the namespace std. Once you start using namespace std then you do not have to keep setting the scope.)

sfuo 111 Practically a Master Poster

A way you can do this is use the function

void SendString(const char* string);

and if your input variable is a string type then for passing it into the function put

SendString(input.c_str())
sfuo 111 Practically a Master Poster

Are you using the variable type string or char[]?

sfuo 111 Practically a Master Poster

If you are tying in "test test" it will put test for the 1st input prompt and test for the second. And this will result in giving you a single output of test.

remove std:cin >> input; ( scope is :: not : ) and this should work.

sfuo 111 Practically a Master Poster

put

cin.ignore()

before the getline() code

sfuo 111 Practically a Master Poster

cin goes till a ' ' or '\n' character comes up.
getline() goes until a '\n' character.

sfuo 111 Practically a Master Poster

What do you want to know? Do you have a compiler?

sfuo 111 Practically a Master Poster

I'm going to assume scanf() is like cin in the way that it cannot take in spaces.
One way to use cin to take in spaces is to use getline(cin, variable).
Then use cin.ignore() if you run into a problem with the '\n' character skipping inputs afterward.

sfuo 111 Practically a Master Poster

Your welcome.

I learned lots out of this too so its win win.