1,362 Posted Topics
Re: Determine which column to sort on. Sort as you would a 1D array. Make sure you keep all the items in a row together when you do the exchanges. | |
Re: The modulus operator's role is to return the remainder (leftover) from integer division. For example, 17 / 5 gives a quotient of 3. What about the remainder, 2? That we can get with modulus. 17 % 5 gives 2. When a number divides fully into another, modulus gives a value … | |
Re: Line 95, you test i < k. What value is k? Since it is unitialized, there is no knowing how many iterations of the loop will occur, probably going past the end of valid data in the array. Are you looking for the oldest girl or youngest girl. Your naming … | |
Re: Or better, move the return statement to end of the function so that the .close() will be executed as well. | |
Re: Another technique is use the fact that the colon separates the fields, using it as a delimiter in the getline. This separates the items for you. std::string input; while( getline( infile, input, ':' ) //reads first element of record { //output the first item getline( infile, input, ':' ); //read … | |
Re: The statements at lines 21 and 23 don't do anything. You need to assign the value in a[i] to one or the other of the two target arrays. Also, don't test i for odd or even, test the value at a[i]. Lastly, you can't use i as the index into … | |
Re: The problem with the hand value is that when you shuffle the deck, you initialize the face cards to values 11-13, which you need to distinguish what they are. But when you use them to add up a score, you must use value 10. So you need to disginguish between … | |
Re: The code above works fine for me in Visual C++ 2010. You might try a `infile.clear( );` before you attempt to open the file again inside the loop. | |
Re: After you read in the grades with the extraction operator ( >> ), a newline is left on the input stream. When you then use getline again, it sees the newline and quits. You need to remove that newline. Perhaps file.ignore( 10, '\n' ); This will throw away up to … | |
This is for the more experienced folks. Recently I found that in Visual C++ 2010 (and 2012, not sure about earlier versions) one can use a std::string as the file name argument for the .open( ) function. I've always known the .open( ) function to take only char* (C-style) strings … | |
Re: In VC++ 2010 it compiles and runs. Do you have some sample input and the corresponding output you expect? gazzatav: The use of the command line arguments for main are optional. If your program doesn't expect arguments, you need not enter them in your code. It is not a compiler … | |
Re: Can you show more code, such as where you actually call the function? It looks like you're trying to pass a single Shoe object as the actual argument, rather than the array of Shoes | |
Re: To know how many seats are available in each row, you need to use the same loop structure you have in the DisplaySeats( ) function to count up the number of seats marked available as you loop through each row. Be sure to reset your counter to 0 as you … | |
Re: You are asking two different questions. To find the length of an array (the amount of storage allocated to it), you can use the sizeof( ) operator, but only in the function where the array was allocated. As in: [code] int arr[] = { 1, 2, 3, 4, 5, 6 … | |
Re: You know you are old when you read all these "you know you are old when" posts and think, "What are these young whippersnappers talking about?" | |
Re: That sounds like the drive mechanism is damaged. If so, not much an end user can do. If you google: "hard drive recovery service" you'll find many outfits that can recover your data. It's a matter of how much it's worth to you. Consider that [URL="http://www.ontrackdatarecovery.com/"]OnTrack [/URL]was able to recover … | |
Re: Whatever's playing on [URL="http://www.offshoremusicradio.com/"]Offshore Music Radio[/URL] via its iTunes radio channel. Reliving the days of Radio Caroline and her sister ships. | |
Re: Here's a couple links to command line argument help: http://malun1.mala.bc.ca:8080/~wesselsd/csci161/notes/args.html http://www.cprogramming.com/tutorial/lesson14.html As to running your program, be sure you opening the command window in the folder where the .exe file is located. That's the file you execute as in c:\dev-cpp\bin\> myprog.exe If you are unfamiliar with working at the command … | |
Re: You should check where the program crashes, and read the error message(s). Check your arguments closely - what's being used here, and what is being used without having a value assigned? [code] intResult = divide(number1, number2); //getAnsers from the user getAnswer(number1, number2, action, answer); //win or loss diviGame(result, static_cast<int>(answer), diviWins, … | |
![]() | Re: Sounds like a possible use of recursion, depending on how similar each layer of the looping is. |
Re: Two points: C++ string is not required to have NULL terminator ('\0'), but you will find it present under many compilers. One should not use this as a limit on the extent of the string, use the .length() or .size( ) methods. C-style strings end with '\0', not '\n'. The … | |
Re: So if someone downloaded the pirated file over a secured, paid for connection, [I]Liberty [/I]wouldn't have any issue with that provider, just the actual downloader? I think their reasoning is, since the free-loading downloader is unidentifiable, they have to try and snag someone. How about the owner of every router … | |
Re: The loop control is the big problem in the logic. [CODE] while(file1.good()) [/CODE] won't stop the process till the file reading fails. If the file is ended properly (with a newline) the loop will process all lines, then will enter again, read the blank line, have nothing to process but … | |
Re: Users of version 1.0 of anything are really paying to be Beta testers. | |
Re: I always keep IrfanView around for quick viewing and basic editing of images. | |
Re: Oops, let's clear this up. cin.get( ) does just what it says - it gets a character from the input stream. Any character, including whitespace (blank, tab, newline). You can use it two ways, for this simple purpose: [code] char ch; cin.get( ch ); //or ch = cin.get( ); [/code] … | |
Re: One of the things you are doing correctly is passing the file handle to the function. However, in main( ) you're making some mistakes with the filename variable. Line 18 - you're declaring the filestream and initializing with the filename variable - but that variable has no value. You don't … | |
Re: Your problem is, how many of a coin do you get from the money? How do you do this in real life? Take 83 cents as an example. How many halves come out of that? How did you determine that? If half dollars were not available (quarter being your biggest … | |
Re: Without your problem statement or the input you used it's hard to know just what your results should be. Offhand, I'd hazard a guess that you should be adding the raise to the annual wage before calculating the next year's raise. Something like [icode]wage = wage + (raiseMoney * i);[/icode] | |
Re: FireFox by default. IE7 when something absolutely demands it. | |
Re: How about [URL="http://www.youtube.com/watch?v=X1tmuq8xufo&feature=related"]this[/URL]? | |
Re: [QUOTE=GrimJack;747270]I keep finding these [URL="http://www.projectcensored.org/top-stories/articles/3-infragard-the-fbi-deputizes-business/"]scary stories[/URL]! I sleep well but sometimes I fear (for) the future.[/QUOTE] There's nothing scary at all about [URL="http://www.infragard.net/"]InfraGard[/URL]. It's about education and information sharing. The members and member organizations have no police powers, can't do anything anyone else can't do. That story is so full … | |
Re: Two things about the code jump out [code] student::student_id() { int sId=000; } student::student(string n, int i) { n=sName; i=sId; } [/code] In the first function above, you are declaring sId, where it's already a datamember of the class. And you don't need a constructor for the data member, you … | |
Re: The only case I'd make for Win98 is if you have some hardware or software you need, that cannot work (or work well) on later versions of Win. For me, it's a large format printer that never got drivers in XP that fully use its capabilities. | |
Re: Two things that jump out at me. 1 - there's no question asked. You won't get much help if you don't point us in the direction of where you're having trouble. 2 - see the sticky posts at top for information on good posting. Especially, use code tags, like this: … | |
Re: When every one of your accounts has a unique, random password, and you can remember them all. | |
Re: Hmm, I thought I was in the C++ forum. Oh, I am! This C code works for me, I see the numbers. How are you viewing the resulting data files? Keep in mind that putw() is writing an int to the file, not the ASCII values representing the numbers. | |
Re: Part of the above advice is not pertinent to your problem or your code. [icode]i < scores.size()[/icode] does not give you size of your array. It would be a good idea to make the loop limit test in your functions use variables for rows and columns, and pass those sizes … | |
Re: Elizabeth Taylor Hilton Wilding Todd Fisher Burton Burton Warner Fortensky | |
Re: To start with, you're trying to decrypt the original input string! [code] string temp=encrypt(code,pass); cout<<"Encrypted Code: "<<temp<<endl; string temptwo=decrypt(code,pass); ///should be (temp, pass) cout<<"Decrypted Code: "<<temptwo<<endl; [/code] Fix that, and it works. | |
Re: What WaltP gave you is a version of Bubble Sort. You can find many explanations and references on the 'net. To compare one string in your array to another, yes, you use only the first index. As in [code] order = strcmp( arr[j], arr[j+1]; [/code] | |
Re: [code] for(i=0;[B]i<=3[/B];i++) { for(j=0;[B]j<3[/B];j++) { //input } } for(k=0;[B]k<3[/B];k++) { for(l=0;[B]l<3[/B];l++) //output [/code] Look at the difference between the loop test in your input and output sections? Shouldn't they be the same? Or at least use the same relational op? | |
Re: Your zip file appears to be corrupt. At least according to my copy of WinZip. | |
We use bumper stickers to proclaim our political/religious/moral/immoral/humorous and other feelings. If you could post a new bumper sticker on your vehicle every day, what would it say today? (Please, one post per day) [b] Do you drive in a phone booth? Hang up NOW! [/b] | |
Re: I don's see you doing anything to test if a set of inputs is in order to begin with. Before you sort the strings, check their order, using code similar to the first block in your sort, setting a flag if an out of order pair is seen. | |
Re: I started answering questions here to give back. I got a good piece of code from one of the DaniWeb contributors, and felt it was worth it to help out some. It also helps me be a better teacher in seeing more problems that students have, and working out how … | |
Re: The avg( ) function is working fine for me. You should perhaps do an output of the values after the sort, to be sure that you've not corrupted the data there. Just what do you mean by "a tad wanky"? If it's not correct, it's not correct. | |
Re: Line 35 - what's 'i' doing there? I take it your loop at lines 34,35 should be displaying just the high temps and you will write a similar loop for the low temps? So, how are you pointing to the correct row of temp data? | |
Re: You don't need both time.h and ctime. Just ctime is sufficient. Are you defining a function srand() in your codefile asteroidsgame.cpp? It also helps to typecast the return from time() to an unsigned int to make srand( ) happy. Your use of rand() is OK, assuming you are looking for … | |
Re: Welcome to DaniWeb First, it does help to put the code in code formatting, like this: [noparse][code] your code goes here [/code][/noparse] Second, please try to be more specific in your question - such as what incorrect result do you get (and what should the correct result be), what error … |
The End.