789 Posted Topics
Re: Indentation (and whitespace in general) is important for anyone who ends up reading the code. That includes the person who wrote it. The readability of properly indented code is very much greater than unformatted code. | |
Re: try putting [inlinecode]cin.get();[/inlinecode] before your return statement. | |
Re: We can help you, but first you have to help yourself. Try to solve the problem first and when you get stuck, ask a question; we won't do your homework for you. If you get stuck with designing your solution, at least post some pseudocode. If your code isn't doing … | |
Re: 1) Post some code. Unfortunately, crystal balls are a bit out of the budget, so we can't see what's wrong. 2) A 9-year old book is... well, almost antiquated. Consider getting a new one, since C++ has been standardized since your book was published. Some compilers may have problems with … | |
Re: [quote=asm_2;263032]-If u have a slower I/O unit, then can the CPU execute instructions while waiting on slower I/O? -In this case, this type of optimization works differently for different I/O units... -So why are there no smarter .exe files that orders the instructions for your I/O-usage? -Whouldn't that be a … | |
Re: You might reconsider using an int as your parameter type. You're limited to 10 binary digits, which leaves you with binary values from 0 - 1023 decimal (at least on my system). If that's fine for your needs, then so be it; otherwise you might consider using a long or … | |
Re: Also, you probably want to compare barometer to a range, rather than a specific value. Perhaps something like: [code] // assuming storm is low, and better weather is higher if(barometer <= storm) // ... else if(barometer <= rain) // ... else if(barometer <= fair) /* etc... */ [/code] The ranges … | |
![]() | Re: Since you didn't specify whether you understood, I'll try to explain it briefly. Say you have the following code: [code] class MyClass { public: int x, y; MyClass(int a = 0, int b = 0) { x = a; y = b; } };[/code] You can change the values with … ![]() |
Re: offhand I'd say it looks fine, though you may consider inputting each one and checking it separately. That way if the 2nd assignment is wrong, you don't have to input the other 3 again. | |
Re: [quote=Harkua;262888]do{ blah blah blah } while (yearcount!=5) That should help you a little.[/quote] Unless I missed something, the loop will go as long as [inlinecode]amount < famount[/inlinecode], assuming amount is updated to store the amount after a given time period. | |
Re: That doesn't look right. Each of statements in the innermost loop take constant (or close enough) time. What will change the execution time of this code is the loop conditions, both of which depend linearly on n. As they're nested, you have a situation of: [code]Outer loop, executes in O(n) … | |
Re: Spacial here too, but like WolfPack, I'm pretty sure I got all but maybe 1 of the objective questions right (I figure the "choose which is least like the others is somewhat subjective). I was clicking through the ads and noticed a small "No Thanks" link in the corner of … | |
Re: [quote=darkeinjel04;262256]I have Made a new program..but still there is a error declaration... i realy nid this program tomorrow so pls help me....re check [/quote] Why should we have to check your code? You should be able to tell if it works or not. And then if you have a problem, … | |
Re: You answered 90% of questions correctly. I missed 5 and 8... not too bad, though I should know 8 (I've missed similar questions way too often) | |
Re: Let's just look through your code and figure out why it give a backwards result: [code][COLOR=#0000ff]while[/COLOR]((input % 10) != 0) { number=input%10; input=input/10; [COLOR=#0000ff]switch[/COLOR](number) { // cases... } [/code] Each iteration of the loop takes the least significant digit and reads that one to you. What you're wanting is to … | |
Re: No. Unless 3n2/2 is supposed to mean (3n^2)/2, which is something of a deduction... Let's work this out from the inside out, starting with [inlinecode]printf("Hello World");[/inlinecode]. This'll execute in (approx.) constant time. Now we've got a loop. This loop will execute i times (0 to i-1). For each iteration of … | |
Re: This sounds somewhat suspicious (very useful for a malicious program) but I could be wrong... I believe you could have the program open a file in the target directory, named as you wish the backup to be called. If the file exists, nothing's left to do. Otherwise you'd have to … ![]() | |
Re: you might look at [URL="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_strtok.2c_.wcstok.2c_._mbstok.asp"]strtok()[/URL] though I don't know that the MSDN page is particularly easy to understand... [edit:] if you need to use std::string, you could either use the .c_str() method or see if there's a split() function (I don't remember if it has one offhand). | |
Re: [quote=LieAfterLie]Okay, I've finished learning C++.[/quote]HAHAHA:lol: [quote=LieAfterLie]What can I do with it? Specifically, I want to do some graphics stuff, anything beyond iostream and fstream. What comes after C++? I know it does more than this. [/quote] Come up with a project. Once you know what you want to write, either … | |
Re: I'd first off recommend using return types instead of pointers. Handling pointers like that (imho) just makes the code messier than it needs to be. You could do it with references instead of pointers as well. And instead of keeping endfile as a variable, just use [inlinecode]f.eof()[/inlinecode]. I'd also suggest … | |
Re: floating point numbers always have a degree of imprecision. A floating point value will never be equal to a whole number. You should check to see if it is within an acceptable epsilon from a whole number (or fractional value, if such a situation were to arise). [inlinecode](loanYears <= floor(loanYears) … | |
Re: Your code probably shouldn't compile. [inlinecode]add(int, int)[/inlinecode] is specified to return an int, but doesn't, which should raise a compile time error. | |
Re: Please don't [URL="http://www.daniweb.com/techtalkforums/thread55213.html"]double post[/URL] | |
Re: If you have [inlinecode]someIstream >> someString[/inlinecode] it will read up to the first whitespace. Try [inlinecode]getline(infile, name)[/inlinecode] after you get the 3 integers. (I haven't used C++ for a while, so I might be remembering getline wrong; if someone can confirm that I'd appreciate it.) | |
Re: [code]switch(value) { case possibleValue1: // do something break; case possibleValue2: // do something break; /* ... */ default: // value wasn't any of possibleValue[1,n] // do something }[/code] Post some code, or some sort of attempt if you want more help ;) | |
Re: First start out with a simple skeleton code: [code]class Main { public static void main(String [] args) { } }[/code] Now, let's think about what we need to do. We probably should prompt the user to enter the numbers (even though you know it takes 2 numbers, prompts make it … ![]() | |
Re: The easiest way would be to put a big loop around the main part. You could have your menu contain an extra option to quit, and just keep doing calculations until they enter that option. | |
Re: [code] #include<stdio.h> [B]int[/B] main() // main's return type is int { /* ... */ b= m%2; // I'm assuming you mean [B]n%2[/B] while( b!= 0) // this will check if [B]n[/B] is even or odd. if it's even, the loop will be skipped. See below. [/code] [quote="the.future.zone"] The loop has … | |
Re: It would be nice if we knew what the problem was (saves us time figuring out where to start). | |
Re: basically, you should put code segments between [noparse][code] and [/code][/noparse] tags. It looks like this: [code]Your code will be in here and formatting will be preserved so we can all read it[/code] If you want to point out a specific line, you can use [noparse][inlinecode] and [/inlinecode][/noparse], which looks something … | |
Re: [quote=govinda.attal;252142]This code does compile and generates an exe file...When I went thru disassembly, I found nothing useful in it...There were no nops in it. First of all our basic coding principles say that it should give a compiler error... compilers like msvc, gcc simply pass without giving any error or … | |
Re: First off, lets look at two code segments. The first is your original while loop, the second is writeTotal. [code]/* ... */ // the while loop: while (!inStream.eof()) { writeTotal(letterCount); } /* ... */ // writeTotal void writeTotal(int list[]) { int index; for(index=0; index<26; index++) cout << static_cast<char>(index+static_cast<int>('a')) << "(" … | |
Re: I'd agree with Grunt. But to make my post somewhat meaningful, I though I'd also point out that you made b of type [inlinecode]unsigned long double[/inlinecode]. I'm thinking that you don't want a floating point value if you're doing integer operations (especially if you're using bitwise operators). | |
Re: [inlinecode]~a[/inlinecode] flips the bits in a, but doesn't save the result anywhere. On the next line, a is still equal to 0xffff. 0x marks that the value is written in hexadecimal (simlarly, a number preceded by a 0, such as 024, is written in octal). Lastly, and unsigned int is … | |
Re: [quote=Anonymusius;251672]But in small programm's like this doesn't it really matter, but in large programm's is it an bad habbit.[/quote] A bad habit is a bad habit, no matter what size the program is. Sure, it can be easier for a small program, but that doesn't change things. Same could be … | |
Re: Well, you've got a good start. Couple of tips: a) use [noparse][code] and [/code][/noparse] tags when you post code, so that formatting is preserved. Makes your code more readable for those trying to help ;) b)your [inlinecode]public boolean trial[/inlinecode] should not be inside main. Make sure there is a closing … | |
Re: [quote=Antiparadigm;251446]The line: [code] jfWindows.setDefaultCloseOperation(EXIT_ON_CLOSE); [/code] Has to be implemented in an action listener right?[/quote] You can just put it in main once you've created the JFrame. It's just a call to a method, afterall ;) | |
Re: Sounds a lot like introsort, but that uses heapsort instead of mergesort... |
The End.