sfuo 111 Practically a Master Poster

What do you mean remove? The way that stuff works is on the next draw you can just not show it but once something is drawn it is there for that frame.

sfuo 111 Practically a Master Poster

Just to double check is this a program that will run through the "map" and will move the knight to all accessible open squares?

sfuo 111 Practically a Master Poster

You are recalling the function so it will never run the if statement I commented.

for(int x = 0; x < 8; x++)
{
	if(checkPosition(r + moveRow[x], c + moveCol[x], size))
	{
		count++;
		movePosition(r + moveRow[x], c + moveCol[x], size, count);
		if(count < (size * size)) //this never runs
		{
			int row = (r + moveRow[x]);
			int col = (c + moveCol[x]);
			board[row][col] = 0;
			count--;
		}
	}

	if(count < (size * size))
	{
		board[r][c] = 0;
		count--;
	}
}
sfuo 111 Practically a Master Poster

This is the C++ forum and you don't as people to do your assignments or whatever that is without showing some input other than what you want your output to be.

sfuo 111 Practically a Master Poster

infile >> name only takes in the first name not both first and last because like cin, your infile will stop at a '\n' new line character or a space character.

sfuo 111 Practically a Master Poster

infile >> name only takes in the first name not both first and last because like cin, your infile will stop at a '\n' new line character or a space character.

sfuo 111 Practically a Master Poster

A char is for a single character meaning if you type in "Hello" it will only save the 'H' to the char variable.

You can make a char array char myarray[size]; This will be able to hold as many characters in it as you have "size".

Or you can include the string header. #include <string> A string is similar to a character array but you do not have to specify the size of it upon declaration. string mystring; I would go check out this website for learning the basics of C++ it helped me out. here.

sfuo 111 Practically a Master Poster

I don't know why you are putting two numbers into your month function to return one number.

Are you trying to take the number month and convert it into a word?
For example:
1 = January
2 = Febuary
3 = March...

If so try this.

string monthConverter(int num)
{
	string monthout;
	switch(num)
	{
		case 1:
			monthout = "January";
			break;
		case 2:
			monthout = "Febuary";
			break;
		case 3:
			monthout = "March";
			break;
		case 4:
			monthout = "April";
			break;
		case 5:
			monthout = "May";
			break;
		case 6:
			monthout = "June";
			break;
		case 7:
			monthout = "July";
			break;
		case 8:
			monthout = "August";
			break;
		case 9:
			monthout = "September";
			break;
		case 10:
			monthout = "October";
			break;
		case 11:
			monthout = "November";
			break;
		case 12:
			monthout = "December";
			break;
		default:
			monthout = "Invalid";
			break;
	}
	return monthout;
}
sfuo 111 Practically a Master Poster

The program runs perfectly and draws fine but when you do a x rotation the y axis changes so then when you do a y rotation on that it ends up rotating the z axis. I kinda dropped this mini project for now just because I see now if I want it to work I have to change a whole bunch of stuff.

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

Yeah I changed something in my post before testing it and it actually doesn't work the way it should. Good job getting it done.

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 would do what Clinton Portis suggested. I wouldn't try doing this without some form of container otherwise you are really restricted with the amount of student records you have and the code becomes extremely bulky.

sfuo 111 Practically a Master Poster

Why don't you try asking nicely. I looked at all 3 of your posts on this forum and they are all super demanding as if you are expecting people to do work for you as if you are some boss.

sfuo 111 Practically a Master Poster

Your name_first and name_last variables are char arrays.
And I find it funny how your teacher would show you how to make structures before arrays but I guess I learned in a different order.
The best thing to use would be a vector container but using an array would work too.

sfuo 111 Practically a Master Poster

I made a snippet here.
This takes in integers and stores them to a multidimensional array.

sfuo 111 Practically a Master Poster

This program asks for integers from the user and stores them into a multidimensional array that adjusts its size.

sfuo 111 Practically a Master Poster

I know a way of doing this and I'll post an example for you but what kind of data do you want? Do you want it to be an array of cstrings?
List[length][numberofentries]
or
List[row][col]

sfuo 111 Practically a Master Poster

Took me a while but I got it.
This uses only one cout << '*'; and according to the first post and my last post the outputs are not side by side but one below another.

I know there are no comments but the whole thing was confusing enough for myself.

#include <iostream>
using namespace std;

int main()
{
	for( int i = 0; i < 4; i++ )
	{
		for( int c = 0; c < 10; c++ )
		{
			int sadd = 0, fadd = 0;
			int xstart, xfinish;
			switch(i)
			{
				case 0:
					xstart = 1;
					xfinish = 10;
					
					fadd = -(9-c);
					break;
				case 1:
					xstart = 10;
					xfinish = 1;
					
					sadd = c;
					break;
				case 2:
					xstart = 1;
					xfinish = 10;
					
					sadd = c;
					
					for( int x = 10; x > 10-c; x-- )
						cout << ' ';
					break;
				case 3:
					xstart = 10;
					xfinish = 1;
					
					fadd = -(9-c);
					for( int x = 1+c; x < 10; x++ )
						cout << ' ';
					break;
			}
			
			if( xstart > xfinish )
			{
				xstart *= -1;
				xfinish *= -1;
			}
			
			for( int x = xstart+sadd; x <= xfinish+fadd; x++ )
				cout << '*';
			cout << endl;
		}
		cout << endl;
	}
	
	system("PAUSE");
	return 0;
}
restrictment commented: Great programmer! +1
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

Well are things wrong with my code:

1) I based it off the picture and the 3rd shape was slopped and now I see you edited that so my output is wrong now.
2) The shapes you showed are all side by side but if you read what the assignment says it wants them one below another.

I am rewriting it now so it should work.

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

So the way I did it was wrong? I don't see how you could do it with only one cout << "*"; statement for all the shapes.

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

What do you mean? You have more than one in your example code you posted.

sfuo 111 Practically a Master Poster

The spacing between A and B is changed because it was huge but other than that its the same.

#include <iostream>
using namespace std;

int main()
{
	for( int i = 1; i <= 10; i++ )
	{
		for( int c = i; c >= 1; c-- )
			cout << "*";
		for( int c = 15-i; c >= 1; c-- )
			cout << " ";
		for( int c = 10; c >= i; c-- )
			cout << "*";
		for( int c = 5; c <= 6+i*3; c++ )
			cout << " ";
		for( int c = 10; c >= i; c-- )
			cout << "*";
		for( int c = 26-i*2; c >= 1; c-- )
			cout << " ";
		for( int c = i; c >= 1; c-- )
			cout << "*";
		cout << endl;
	}

	system("PAUSE");
	return 0;	
}
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

I posted the answer in my attachment and you ended up just reposting what you put up in your 1st post.

I took my code and deleted a whole bunch of stuff and changed the find character from ' ' to '-'. This stores everything to a vector but you can change it to a char* array[3] if you want to but I'll leave you to think that part up.

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
	string sentence, word, charString, wordString;
	vector<string>wordlist;
	
	cout << "Please enter some words (ctrl-d or ctrl-z to quit): " << endl;
	
	while(getline(cin, sentence))
	{
		wordlist.clear();
		int lastSpace = -1;
		
		for( int i = 0; i < sentence.length(); i++ )
		{
			if( sentence[i] == '-' )
			{
				word = sentence.substr(lastSpace+1, (i-lastSpace-1));
				wordlist.push_back(word);
				lastSpace = i;
			}
			else if( i == sentence.length()-1 )
			{
				word = sentence.substr(lastSpace+1, (i-lastSpace));
				wordlist.push_back(word);
			}
		}
		
		if( wordlist.size() > 0 )
		{
			for(int i = 0; i < wordlist.size(); i++)
			{
				cout << wordlist[i] << endl;
			}
		}
		else
		{
			cout << "You didn't enter any words." << endl << endl;
		}
		
	}
    system("PAUSE");
    return 0;
}
sfuo 111 Practically a Master Poster

You can use the substr() function to copy part of a string to another string.
I find this website really good for stuff like this here.
That is a link to the substr() reference but there is a whole lot of examples for other class functions.

Added an example program I made for an assignment that takes in a sentence and stores all the words into a vector. You can use this example and instead of looking for a space character look for the '-'.

sfuo 111 Practically a Master Poster

First of all the output will always be greatest to smallest.
Second I didn't spend a whole lot of time taking out the repeat conditions and I mentioned on the post that he would have to do some merging if he wanted it to look cleaner.

sfuo 111 Practically a Master Poster

You pretty much have it as while 'Q' is false.
'Q' is 'Q' not true or false.
You want it as while valid is false and valid becomes true when a valid season is picked.

sfuo 111 Practically a Master Poster

I did this with using the numbers 1 2 3 4 for testing. You can merg all of this into 1 if "tree" if you want but I was getting confused enough when working this out.

#include <iostream>

using namespace std;

int main()
{
	int n1, n2, n3, n4; //n for number
	int o1, o2, o3, o4; //o for order

	cout << "Input number 1 of 4: ";
	cin >> n1;
	cout << "Input number 2 of 4: ";
	cin >> n2;
	cout << "Input number 3 of 4: ";
	cin >> n3;
	cout << "Input number 4 of 4: ";
	cin >> n4;
	
	if( n1 >= n2 )
	{
		if( n1 >= n3 )
		{
			if( n1 >= n4 )
			{
				o1 = n1;
				if( n2 >= n3 )
				{
					if( n2 >= n4 )
					{
						o2 = n2;
						if( n3 >= n4 )
						{
							o3 = n3;
							o4 = n4;
						}
						else
						{
							o3 = n4;
							o4 = n3;
						}
					}
				}
				else if( n2 < n3 )
				{
					if( n3 >= n4 )
					{
						o2 = n3;
						if( n2 >= n4 )
						{
							o3 = n2;
							o4 = n4;
						}
						else
						{
							o3 = n4;
							o4 = n2;
						}
					}
				}
				else if( n2 < n4 )
				{
					if( n4 >= n3 )
					{
						o2 = n4;
						if( n2 >= n3 )
						{
							o3 = n2;
							o4 = n3;
						}
						else
						{
							o3 = n3;
							o4 = n2;
						}
					}
				}
			}
		}
	}
	if( n1 …
sfuo 111 Practically a Master Poster

He said you can't use any logical operators.

sfuo 111 Practically a Master Poster

Does it have to have the nested if-else statements or can you just use a vector to store all the ints in and then sort the vector?

sfuo 111 Practically a Master Poster

You can't change the data type of a variable.

sfuo 111 Practically a Master Poster

I am making a rubix cube game in OpenGL and I have run into a problem with rotations. When doing multiple rotations (x, y, z) the axis gets rotated as well (ie when doing an x-axis rotation of 90 or 270 deg the y-axis becomes the z-axis and z-axis becomes the y-axis).
Is there any way to stop the axis from rotating but allowing the object to translate or is there a trick to get around this.

Here is a small part of my code for the translations.

glPushMatrix();
	glRotatef(xrot, 1.0, 0.0, 0.0); //rotates the unit cube into place
	glRotatef(yrot, 0.0, 1.0, 0.0);
	glRotatef(zrot, 0.0, 0.0, 1.0);
		
	glTranslatef(xoff, yoff, zoff);  //translates the unit cube into place
		
	glRotatef(xrotset, 1.0, 0.0, 0.0); //rotates the unit cube in its place 
	glRotatef(yrotset, 0.0, 1.0, 0.0);
	glRotatef(zrotset, 0.0, 0.0, 1.0);

	glBegin(GL_QUADS); //draws the cube
		for( int i = 0; i < unitIndices.size(); i++ )
		{
			GLint *curIndices;
			curIndices = unitIndices[i].getVals();
			glColor3fv(unitColors[i].getVals());
			glNormal3fv(unitNorms[i].getVals());
			glVertex3fv(unitVerts[curIndices[0]].getVals());
			glVertex3fv(unitVerts[curIndices[1]].getVals());
			glVertex3fv(unitVerts[curIndices[2]].getVals());
			glVertex3fv(unitVerts[curIndices[3]].getVals());
		}	
	glEnd();
glPopMatrix();

This is just how I have the drawing for each unit cube 27 of these make up the "rubix cube". The problem lies in the xrot, yrot and zrot lines.

Thanks.

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

Way to make 3 threads about one thing at the same time.

sfuo 111 Practically a Master Poster

Take a look at this thread. I think this is what you are looking for.

sfuo 111 Practically a Master Poster

OK you will have to change lots of things for what you need but this searches a sorted file for a date using a binary search.

#include <fstream>
#include <iostream>
#include <string>

using namespace std;

bool greaterThan(string a, string b)
{
	//format mm/dd/yyyy
	int Ya = atoi(a.substr(6, 4).c_str());
	int Yb = atoi(b.substr(6, 4).c_str());
	
	int Ma = atoi(a.substr(0, 2).c_str());
	int Mb = atoi(b.substr(0, 2).c_str());
	
	int Da = atoi(a.substr(3, 2).c_str());
	int Db = atoi(b.substr(3, 2).c_str());
	
	if( Ya > Yb ) //compares years
		return true;
	else if( Ya < Yb )
		return false;
	
	if( Ma > Mb ) //compares months
		return true;
	else if( Ma < Mb )
		return false;
	
	if( Da > Db ) //compares days
		return true;
	else if( Da < Db )
		return false;
}

int main()
{
	bool found;
	int minP, midP, maxP;
	string minS, midS, maxS;
	string finding = "22/22/2222"; //date to find
	ifstream in;
	
	in.open("text.txt", ios::ate);
	
	//my text.txt was
	/*
	00/00/0000
	11/11/1111
	22/22/2222
	33/33/3333
	44/44/4444
	55/55/5555
	66/66/6666
	77/77/7777
	88/88/8888
	99/99/9999  //make sure that there is a newline at the end of the file
				//otherwise it does not work because it is not all 12 base
				//(10 date characters and 2 for newline character)
	*/
	
	in.seekg(-12, ios::end); //start of the last date
	maxP = in.tellg();
	in >> maxS;
		
	if( maxS == finding )
	{
		found = true;
		cout << "FOUND" << endl;
		cout << maxS << endl;
	}
	
	in.seekg(0, ios::beg); //start of the first date
	minP = in.tellg();
	in >> minS;
	if( minS == finding )
	{ …
sfuo 111 Practically a Master Poster

When I think of Mad Libs I think of a preset sentence with blanks in it. You are asked to fill in the blanks with the type of word needed and then you read out the sentence with your words.

For this I would make up like 5 sentences and randomly pick one then ask for user input based on what you need (noun, verb, etc.) and then output the completed sentence with the users input.