1,608 Posted Topics

Member Avatar for TheWolverine

If you have a system with 1000 particles the information you will need to save/enter will be the same whether you have individual particles, arrays of attributes or a container of particles. Who said you won't have to worry about out of bounds checking when using vectors? To my knowledge …

Member Avatar for TheWolverine
0
172
Member Avatar for caramel

One method to right justify shorter string: Determine the lengths of A and B Determine which string is longer Determine the number of zeros to prepend to the shorter string Create a string of zeros to prepend to the shorter string Concatenate the string of zeros and the shorter string

Member Avatar for dusktreader
0
974
Member Avatar for PDB1982

HotDogStand.DogCounter = 0; HotDogStand is a type, not an object, so use of the dot operator in this context is an error. On the other hand, each element of CartSales: CartSales[i] is an object of type HotDogStand, so using the dot operator on each of these objects to allow you …

Member Avatar for WaltP
0
174
Member Avatar for casjackkwok2001

Please learn how to use code tags when posting code to this board. Change this:[code] // Copy to the content for(int i = 0; i < SIZE; i++) for(int j = SIZE; j < SIZE * 2; j++)[/code] to this: [code] for(int i = 0; i < SIZE; i++) //assign …

Member Avatar for Lerner
0
2K
Member Avatar for skorm909

Ideas: 1) consider moving the using statement outside of and before declaring main() 2) Throughout your code you use this syntax: if (actionX == y. || actionX == y) Why? All the actionXs are declared to be ints so the period after the integer, y, may not be doing what …

Member Avatar for skorm909
0
418
Member Avatar for RayvenHawk

>>What I'm wondering is is there a way to randomly display a string array and avoiding duplicates? If I have an array of x unique strings I could write code to display all x strings randomly, but display each string only one time, yes. If that's what you are asking. …

Member Avatar for dusktreader
-1
88
Member Avatar for i_luv_c++

>>is any other way with less steps If you didn't have the restrictions placed on the project, definitely. With current restrictions and without seeing your current code, who knows if it might be done with fewer lines/comparisons or not.

Member Avatar for i_luv_c++
0
149
Member Avatar for josh06

Unless your goal is to be the equivalent of an olympic athlete, I agree with Ancient Dragon. But if you're willing to sacrifice other aspects of your life to the pursuit of a goal you hold passionately I guess that's up to you, as long as you are aware that's …

Member Avatar for josh06
0
118
Member Avatar for gnarlyskim

[code]printing term of polynomial without coeff if coeff == 1 and without exponents if exp == 1 and without variable or exp if exp == 0: if(coeff != 1) cout << coeff if(exp > 1) cout << "x^" << exp; else if(exp == 1) cout << "x"; //else if(exp == …

Member Avatar for gnarlyskim
0
1K
Member Avatar for cassds

The alternative to prefixing "everything" with st:: is to place the line: using namespace std; after the list of includes (in this case between the first two lines of the program). Once you've read further in the book you should learn why this statement isn't necessarily the prefered option, though. …

Member Avatar for cassds
0
831
Member Avatar for arafat_alam

My toe hurts, can you tell me why? That question is admittedly a little worse than yours, but not by much. Tell us what sort of a problem are you having---Program crashing? Not compiling? Runs okay but gives wrong output? Error/warning messages? Some ideas, that may or may not have …

Member Avatar for arafat_alam
0
132
Member Avatar for iamfabian

1) check the file for all string literals Can string literals include embedded quotations? If so, then the project becomes harder. 2) Also, I have to ensure it ignores comments that include quotations. Again, you can use a brute force method or use find() on an STL string to find …

Member Avatar for tetron
0
405
Member Avatar for geoldr

Files work best for saving data, not using data interactively, as the response time for retrieving data from file is slow compared with finding data from within RAM. For doing what you want with 15 words it is much easier to read all the words into a container, and an …

Member Avatar for hag++
0
112
Member Avatar for timbomo

1) if the user doesnt put in a valid response then a message will cum up and they will go back 2 the beginning until they do it correctly. Add another section in the switch statement after the case 'D': that looks something like this: default: cout << "input error. …

Member Avatar for WaltP
0
157
Member Avatar for timbomo

[code]{ //start body of loop .... case 'A': if money_left more than cost-of-A money-left -= cost-of-A increment number-of-items-bought-today money-spent += cost-of-A else sorry you do not have enough money to buy this break; .... } //end switch if money-left not enough to by cheapest item available sorry you do not …

Member Avatar for Lerner
0
118
Member Avatar for timbomo

Declare an int variable for each item you can purchase and initialize them all to zero. Do this at the start of the program. Then increase each variable within the appropriate case statement as an item is purchased.

Member Avatar for Lerner
0
169
Member Avatar for scott6480
Member Avatar for corby

There are two types of lines in your rectangle. The top and bottom line both look alike and all the lines in between have the same appearance. The top and bottom all use the same symbol. The interior lines all have the first and last char the same as the …

Member Avatar for corby
0
181
Member Avatar for timbomo

replace this:[code] cin >> mug; cin >> teeshirt; cin >> pen; cin >> quit; mug = ('A' || 'a'); teeshirt = ('B' || 'b'); pen = ('C' || 'c'); { if ((mug == 'A') || (mug == 'a')) { mug = 2.50; } else if ((teeshirt == 'B') || (teeshirt …

Member Avatar for Lerner
0
109
Member Avatar for khevz09

Use an outer while loop to control the number of line. Within the outer while loop use two loops in sequential manner. The first inner loop will control the number of spaces to print for the line you are on. The second inner loop will print the sequence of numbers …

Member Avatar for tetron
0
84
Member Avatar for tetron

When thinking about a question posted about creating a LargeInteger class the other day I realized that to access the indexes of a string with the [] operator you need to use an int, which has an upper limit in size which is probably less than 1,000,000,000,000, unless the compiler …

Member Avatar for Ancient Dragon
0
1K
Member Avatar for esdftw

Based on representative file lines the following strategy using sequential calls to find() and substr() and using a stringstream to convert an STL string into a numerical data type might work. Below is narrative description of a possible protocol and a rough pseudocode of what it might look like: use …

Member Avatar for esdftw
0
156
Member Avatar for angel6969

The standard deviaion is the square root of the sum of the variations from the average squared divided by the number of elements in the population. numbers is an array of type double N = number of elements ine numbers x = average = sum of all elements in numbers …

Member Avatar for jonsca
0
264
Member Avatar for StaticX

There are any number of ways to do this. If I assume the file has a number of lines of text and each line has two fields, one being a word which is preceded by a space which is preceded by a number, then I would create a class called …

Member Avatar for Lerner
0
109
Member Avatar for terabithia

Before jumping to the math function members have you run your code to see if you can declare a Matrix, delete a Matrix, copy a Matrix and assign one Matrix to another without the program crashing? In particular I have questions about the deletion operator, and the copy constructor. Do …

Member Avatar for Lerner
0
1K
Member Avatar for nucoder

1) I'm having issues with reading data into a 2D array.... It's probably easiest to use a nested loop to read in values. Since it is given there will be 50 ints in the file you can use for loops: int temp;[code] outer loop to control row inner loop to …

Member Avatar for nucoder
0
171
Member Avatar for timbomo

Welcome to the board! There is a number of problems with your code, but since I haven't memorized the meaning of error # 2447 I can't say which one it is. 1) The first thing I would do is remove the semicolon at the end of this line: int main(); …

Member Avatar for Lerner
0
126
Member Avatar for b.bob

to look at an online version of the difference between strcpy() and strncpy() go to cppreference.com and look at Standard C string and Char section. Without further clarification I would expect your first and third versions to fail given that char * needs to have memory assigned to it before …

Member Avatar for dusktreader
0
382
Member Avatar for problemkid

You could do the arithmetic in "two" steps:[code] 1) Determine the sign of the result: A) Addition a) if operands have same sign, then result has the same sign as the operands b) if operands have different signs, then result has sign of the operand with the largest absolute value …

Member Avatar for dusktreader
0
143
Member Avatar for moods125

line 43: you need some way to stop the loop. using a line like: while(!valid); should do it. line 84 should be: return true; else how are you going to indicate that all char in the input are valid char for a roman numeral?

Member Avatar for Salem
0
781
Member Avatar for cpu-guy

I think of an iteration as being a single time through something or a version of something that changes over time. So if I use a loop to increase the value of x by 1 ten times there are 10 iterations to the process. There are 20 some versions/iterations to …

Member Avatar for cpu-guy
0
143
Member Avatar for rwill357

I noticed you have commented out all the calls to display(). I suspect that's because when you try to display the lists you don't get what you expect because the addToHead() function is wrong and all the lists you create in main() use addToHead(). You always assign the new node …

Member Avatar for Lerner
0
395
Member Avatar for wot

jBat describes one way write data to file. You must decide what you want to write to file. The 0x notation won't appear as such in a text file using jBat's protocol. Instead what will appear is the char represented by the integer (0x...) in whatever character set (often ASCII …

Member Avatar for Kurt Kubing
0
160
Member Avatar for Dimitar

There are two logical endpoints to stop calculations. One is based on the width of the boxes. The other is on the variation in the area under the curve; that is, decrease the width of the boxes as much as you need to until the change in the area under …

Member Avatar for nezachem
0
163
Member Avatar for asa88

the header file known as string.h and the string header file in namespace std are not the same. Therefore when using the std:: prefix in declaring string objects in the Car.h file you don't have the correct header file included.

Member Avatar for asa88
0
138
Member Avatar for FatimaRizwan

[url]http://www.cppreference.com/wiki/string/start[/url] That's a reference for the member methods of the STL string class including find_first_of() and subst(). You would probably want to use those two methods in combination to separate out tokens based on the criteria you have. An alternate would be to change the STL string into a C …

Member Avatar for jonsca
0
447
Member Avatar for Eddy Dean

url = sUrl.c_str(); This won't work because you can't assign one Cstyle string to another. At the top of your code add the line #include <cstring> and then use this: strcpy(url, sUrl.c_str()); for the above line. There are other rules for using C style strings. If you are going to …

Member Avatar for Salem
0
2K
Member Avatar for atticusr5

IMO this is the result of the indescriminant use of typedefs. On line 266 TempStudent is declared to be of type StudentArray. Therefore, rather than the :: operator to access member variables of whatever a StudentArray object is, you will need to use one of the following: TempStudent.memberVariable, TempStudent->memberVariable or …

Member Avatar for SasseMan
0
142
Member Avatar for steak-sandwich

How many digits are in each element of basis and how many do you see when printing them to screen in line 35?

Member Avatar for jonsca
0
210
Member Avatar for shaunmccann1

Is the input string a null terminated char array (C style string)? What type is the output to be? What type(s) do you want the token(s) to be?

Member Avatar for shaunmccann1
0
162
Member Avatar for Phil++

If the array of customers may hold less than the maximal number of possible customers then you should keep track of the actual number of customers anyway. Under that scenario you can evalute the actual number of customers. If it's zero, then display menu A and if it isn't, then …

Member Avatar for abdelhakeem
0
107
Member Avatar for dpfaff

??it lets me enter the numbers, but than exits the command prompt right after It may be doing everything you want but just not keeping the console screen open so you can see it because it's not been told to do that. Whern the program is done, the console closes …

Member Avatar for Lerner
0
146
Member Avatar for jegadees

You don't want to reverse the string, you want to reverse the words in the string. First you need to break up (parse) the string into substrings (words). But how are you going to know how many words there are and how will you know which order they are in …

Member Avatar for mrnutty
0
140
Member Avatar for ireimaima

Give neg and pos a meaningful value, probably zero, before trying to use them, just like you did for sum. Pass neg and pos to getNum() by reference. Call countNum() from within loop of getNum(), probably between line 31 and 32, otherwise you will only be able to process the …

Member Avatar for ireimaima
0
154
Member Avatar for DeathEater

Post at least the list of header fies included in your program and the user created header files, particularly the CHESS.H and CHESS.CPP file. Looks like there are some dependency issues with lack of necessary header files. Also indicate what compiler and OS you are using.

Member Avatar for jonsca
0
213
Member Avatar for monocog

You can overload operators to do whatever you want them to, almost. For example, you could overload the % to increment an int by 33 if you wanted. That being said, most overload implementations stick to reasonably traditional actions. So overloading the + operator almost always means addition if it …

Member Avatar for bigsurya
0
129
Member Avatar for damaged

I'd check for denominator equals zero and if not, then call the function passing a, b, result and remainder to the funciton with result and remainder being passed by reference. When the function is done, then print out the numerator, denominator, result and remainder.[code] void div(int temp, const int b, …

Member Avatar for damaged
0
138
Member Avatar for ayan2587

1) How about declaring an array of pointers to pointers to int? Declare memory dynamically for both the array and the pointers it holds and then delete one pointer at a time. 2) How about the reverse of "expanding" an array? Declare temp using enough dynamic memory to hold the …

Member Avatar for Salem
0
181
Member Avatar for ayesha91

I sometimes have problems using the [] operator for STL strings in the fashion you are. I believe this has to do with the default size of an STL string and that using [] doesn't automatically increase size of an STL string when needed whereas other operators like + and …

Member Avatar for Lerner
0
159
Member Avatar for fadia

Line 213 returns an int but line 217 says return type is void. A protocol for calculating time interval between current time and other time might look something like:[code] //detrmine which time is ealier than the other if current time after other time later time = current time earlier time …

Member Avatar for Salem
-3
110

The End.