419 Posted Topics
Re: 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 … | |
This program asks for integers from the user and stores them into a multidimensional array that adjusts its size. | |
Re: First off this is the C++ forum and not the C one but I will show you a way of doing it in C++ since I don't know what headers C++ has and C doesn't. [CODE]#include <iostream> using namespace std; int main() { int input, output = 0; cout << … | |
Re: 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. | |
Re: You are recalling the function so it will never run the if statement I commented. [CODE]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 { … | |
Re: 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. | |
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 … | |
Re: 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 … | |
Re: [ICODE]infile >> name[/ICODE] 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. | |
Re: 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 [ICODE]char myarray[size];[/ICODE] This will be able to hold as many characters in it as you have "size". Or you can include … | |
Re: 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. [CODE] string monthConverter(int num) … | |
Hi, I was wondering if anyone could help me figure out how to see who is connected to you when you are hosting a game on a specific port via c++. I know you can use netstat in cmd prompt and it shows a bunch of info of who you … | |
Re: 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. [CODE]#include <iostream> using namespace std; int main() { char sign; bool end = false; int total = 0, input; cout << "Current … | |
Re: 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 … | |
Re: 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 … | |
Re: Another way to write this would be: [CODE]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; }[/CODE] [CODE]Fraction(int _num = … | |
Re: 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. | |
Re: 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] | |
Re: The spacing between A and B is changed because it was huge but other than that its the same. [CODE]#include <iostream> using namespace std; int main() { for( int i = 1; i <= 10; i++ ) { for( int c = i; c >= 1; c-- ) cout << … | |
Re: 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 … | |
Re: Attach your whole code so I can try running it and see what is going on. | |
Re: 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. | |
Re: 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 [URL="http://www.cplusplus.com/reference/string/string/substr/"]here[/URL]. That is a link to the substr() reference but there is a whole lot of examples for other class functions. Added an example program … | |
Re: 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? | |
Re: 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. | |
Re: You can't change the data type of a variable. | |
Re: 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. | |
Re: For displaying arrays you do not just call the array its self you have to make a for() loop to output. [CODE]for(int i = 0; i < 8; i++) { cout << arr[i]; }[/CODE] | |
Re: I copied exactly what you have and I didn't get any errors. What compiler do you use? | |
Re: Take a look at [URL="http://www.daniweb.com/forums/thread224343.html"]this thread[/URL]. I think this is what you are looking for. | |
| |
Re: 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 … | |
Re: [CODE] #include <time.h> #include <iostream> srand(time(NULL)); char randChar = rand()%(90-65)+65; int makeLower = rand()%2; if( makeLower == 0 ) { randChar += 'a'-'A'; }[/CODE] This generates a capital char then converts it to a lowercase if makeLower is equal to 0. | |
Re: Do you have to use the class word for word? Or can you change some return types and parameters. | |
Re: I think its just checking from a list of options and if it is not there it throws you the error that it does not have a spawn function. | |
Re: So post some sample code of what you have so far. We don't hand out free code for assignments. | |
Re: 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 … | |
Re: Is this where it says the error is? Or can you post all your code if it isn't too long. | |
Re: Why are you calling the prototype with no parameters? This would be the problem that I see. | |
Re: 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 [CODE] … | |
Re: 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. | |
Re: Well we cant give you the solution 100%. I know a bit about winsock for windows and I could help you make a client/server for it but you have to ask questions and I will help answer them. | |
Re: Last post was March 15th, 2006. In the before posting thread it says don't post on dead threads. | |
Re: Can you post a quick input example that would be inside of the textfile. | |
Re: Your return value is the type of function that you declared. For example if you make int sum(int x, int y) { return x+y; } this function returns an integer. Your return value is a set and that is a class type you defined. It looks like you are just … | |
Re: Is this what you are trying to do? This is a very general example [CODE]#include <iostream> #include <string> using namespace std; string myReturn( string in ) { return in; } int myReturn( int in ) { return in; } int main() { string strIn = "20"; int intIn = 20; … | |
Re: I used the nested for() loops for it and I got it to work fine for any input. This is just the function: [CODE]void drawShape(int nrP) { for(int r = 0; r < nrP; r++) { for(int c = 0; c < (nrP*2-1); c++) { if( r == nrP-1 && … | |
Re: Give this a try. [CODE]ifstream infile; ofstream outfile; int size = 1; infile.open("input.txt"); struct Student * data; struct Student * temp; data = new struct Student[size]; int i = 0; while( !infile.eof() ) { infile >> data[i].First >> data[i].Last >> data[i].Score1 >> data[i].Score2 >> data[i].Score3 >> data[i].Score4 >> data[i].Score5 >> … | |
The End.