2,384 Posted Topics
Re: You need to learn how to call a function (among many other things). Back up in your text a bit. [edit]Call [inlinecode]srand[/inlinecode] only once in your program, before you call [inlinecode]rand[/inlinecode]. Use [inlinecode]rand[/inlinecode] to obtain a random number between 0 and [inlinecode]RAND_MAX[/inlinecode]. If you want to narrow the range, a … | |
Re: [url]http://www.daniweb.com/techtalkforums/announcement8-2.html[/url] [url]http://www.daniweb.com/techtalkforums/faq.php?faq=daniweb_faq#faq_rules[/url] | |
Re: Again, be careful with array sizes.[QUOTE=atrusmre] [CODE] for (int i = 0, i <= 2, i++) m_cPeople.AddString( (LPCTSTR)names[i]); [/CODE][/QUOTE]This loop executes 3 times and tries to write from three strings. | |
Re: A struct cannot contain an instance of itself -- perhaps you meant to have a pointer to the next instance in the Node (and elsewhere). | |
Re: Focus your attention here in [inlinecode]deleteNode[/inlinecode]: [code] if(current->info == deleteItem) { trailCurrent = current->back; trailCurrent->next = current->next; if(current->next != NULL) current->next->back = trailCurrent; if(current == last) last = trailCurrent; count--; delete current; }[/code] | |
Re: [QUOTE=smallville]I was able to get that step down using the bubble sort - my problem now is that I need to use arrays and modular programming to get this code to work properly.[/QUOTE]Why not a [inlinecode]std::vector[/inlinecode] and other standard functions such as [inlinecode]std::sort[/inlinecode]? And you may have missed [post=155265]this[/post]. [edit]Oh, … | |
Re: You've just discovered your first reason to dislike global variables! [code]balance = (Interest + 1.0f) * [COLOR=Magenta]B[/COLOR]alance;[/code] | |
Re: [url]http://www.parashift.com/c++-faq-lite/templates.html#faq-35.16[/url] | |
Re: Something similar to this? [CODE]#include <iostream> using namespace std; int main() { cout << "Press [enter] to continue..."; cin.get(); cout << "Hello\n"; return 0; }[/CODE] | |
Re: [QUOTE=wdowell84]One of the problems I'm having is that it keeps saying that local function definitions are illegal. Here's the program so far.[/QUOTE]Because of bad indenting, you can't see that you've actually got this:[code]// TODO: code the display function void display(const int num[], const int size) { // display labels and … | |
Re: What type is [inlinecode]pay1[/inlinecode]?[code] void salary([COLOR=Magenta]pay1[/COLOR]) { cout << "Enter the hourly wage of the worker: $"; cin >> pay1.rop; cout << "Enter the number of hours worked this week: "; cin >> pay1.hours; }[/code]And you cannot define a function within another function. Now would be a good time to … | |
Re: Show us your basic attempt start to the code with [url=http://www.daniweb.com/techtalkforums/misc.php?do=bbcode#code][inlinecode][co[u][/u]de][/co[u][/u]de][/inlinecode][/url] tags. | |
Re: Perhaps it means that you intermingle [inlinecode]hat_size[/inlinecode] as both the name of a variable and a function and the compiler is trying to figure out which one you mean in any particular context. You tell it a couple things and expect it to know which one you mean. | |
Re: [url]http://www.daniweb.com/techtalkforums/thread10232.html[/url] | |
Re: This is not valid C++, and I think it's the start of where you go wrong. [code]T data[size];[/code][edit][url]http://en.wikipedia.org/wiki/Insertion_sort[/url] | |
Re: [QUOTE=Narue]This may come as a surprise, but that's not actually Dave. ;)[/QUOTE]Sure it is. About 1978?[QUOTE=Narue]Nah, he looks goofy. ;) [/QUOTE]This is true. Time and bad habits have not been kind.[QUOTE=Narue]We'd just have to go by his wonderful personality. :twisted:[/QUOTE]Uh-oh. If that's all I've got to go on, I'm in … | |
Re: [url]http://www.sjbaker.org/steve/software/cute_code.html[/url] | |
Re: And you may want to break out of the loop when you find an answer. | |
Re: Did you type two characters -- [inlinecode]'A'[/inlinecode] and a newline? Also, [inlinecode]getchar[/inlinecode] returns an [inlinecode]int[/inlinecode]. | |
Re: First, consider a real code editor instead of something like MS Word that capitalizes unwantedly and automatically. C and C++ are case sensitive. And I'm sure there must be plenty of good, and free, code editors available. Second, it's a bad idea to use [inlinecode]eof()[/inlinecode] to control a loop. Check … | |
Re: [url]http://en.wikipedia.org/wiki/Linear_search[/url] | |
Re: [url]http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.2[/url] But that's probably not applicable. I'd probably look at [inlinecode]s[0][/inlinecode] to see if there is a [inlinecode]'-'[/inlinecode] there. This may look cute or high-tech or something when you're new: [code]j = s[i] - 48;[/code] But later on you'll find out it's better to write it like this. [code]j = … | |
Re: I'd guess that you intended this: [code]if (current > highest)[COLOR=Magenta];[/COLOR][/code]to be this:[code]if (current > highest)[COLOR=Blue]{[/COLOR][/code] | |
Re: [url]http://www.symbian.com/books/index.html[/url]? [url]http://en.wikipedia.org/wiki/Symbian[/url]? [url]http://www.newlc.com/rubrique.php3?id_rubrique=3[/url]? | |
Re: If you had an array of at least two of the objects, and you took the address of adjacent elements, cast each address to a [inlinecode]char*[/inlinecode], and found the difference between each address, you would have the size of one object. | |
Re: This:[code]while(f=fgetc(c)!=EOF)[/code] is equivalent to this: [code]while(f=[COLOR=Magenta]([/COLOR]fgetc(c)!=EOF[COLOR=Magenta])[/COLOR])[/code]But what you want is this:[code]while([COLOR=Blue]([/COLOR]f=fgetc(c)[COLOR=Blue])[/COLOR]!=EOF)[/code]And you likely meant for [inlinecode]f[/inlinecode] to be [inlinecode]c[/inlinecode]. And [inlinecode]c[/inlinecode] should be an [inlinecode]int[/inlinecode]. And [inlinecode]main[/inlinecode] returns an [inlinecode]int[/inlinecode]. | |
Re: Minor tweaks: [code]#include <iostream> #include <string> #include <sstream> #include <fstream> using namespace std; class job { string name; int length, time; string type; char urgent; public: bool read([COLOR=Blue]ifstream &file[/COLOR]) { [COLOR=Blue]return file[/COLOR] >> name >> length >> time >> type >> urgent; } void show() { cout << "name = … | |
Re: Maybe something like this. [code]#include <iostream> #include <iterator> #include <algorithm> using namespace std; int main() { int array[5]; cout << "Input " << sizeof array / sizeof *array << " numbers: "; for ( size_t i = 0; i < sizeof array / sizeof *array; ++i ) { if ( … | |
Re: I think you use manipulators to set a width and zero fill. [code]#include <iostream> [COLOR=Blue]#include <iomanip>[/COLOR] using namespace std; int main() { int mint; cout << "Enter minutes: "; cin >> mint; int hh , mm; hh = mint / 60; mm = mint % 60; cout << [COLOR=Blue]setw(2) << … | |
Re: [QUOTE=simon126]yea i think i got it working if you can please check if i did it properly i would greatly appreciate it. Here is what i came up with.[/QUOTE]Does it do what you expect? Perhaps you could tell us what you expect it to do. If this is what you … | |
Re: Seed the random number generator only once in your program. Move your srand call to main, before your for loops. | |
Re: [url]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1045691686&id=1043284392[/url] | |
Re: [url=http://www.daniweb.com/code/snippet406.html]Quickie concatenation algorithm[/url]. | |
Re: Your function [inlinecode]isFactor[/inlinecode] expects two arguments, but you only pass it one.[code]if ( isFactor ([COLOR=Magenta]num1%2==0[/COLOR]) )[COLOR=Magenta];[/COLOR][/code]The trailing semicolon is likely extraneous and problematic as well. This is an assignment, not a comparison. And again the semicolon ends the loop before the body begins.[code]for ( num2=2; [COLOR=Magenta]num2=1[/COLOR]; num2++ )[COLOR=Magenta];[/COLOR][/code]Also, C++ is … | |
Re: Do you intend to multiply a[x] and b?[code]c=a[x]b;[/code] [Dani - again I'd really love to have fixed-point fonts back. And font sizes for this portion.] | |
Re: I am having a difficult time understanding what it is you are asking. But what I think you want is a function that returns the fibonacci number of the value passed to the function, such that [indent]fib(0) = 0 fib(1) = 1 fib(2) = 1 fib(3) = 2 fib(4) = … | |
Re: A guess:[code]#include <vector> #include <iostream> using namespace std; class Test { public: Test() { cout<<"In TEST constructor"<<endl; } ~Test() { cout<<"In TEST destructor"<<endl; } }; int main() { Test t1; vector<Test> vec; vec.push_back( t1 ); cout<<"About to clear vector"<<endl; vec.clear(); [COLOR=Blue]cout << "done\n";[/COLOR] } /* my output In TEST constructor … | |
Re: This is not a valid format specifier:[code]scanf ("%[COLOR=Red].2[/COLOR]f", &number_gallons);[/code]Just use %f. Don't use this:[code]void main(void )[/code]The function main should return an int. This is undefined:[code]fflush (stdin); [/code]Try never to use it. | |
Re: [QUOTE=shantise2003]I am very new to this and i really need some help :cry: [/QUOTE]Please read the [url=http://www.daniweb.com/techtalkforums/announcement8-2.html]Announcement[/url]. Post an attempt. | |
Re: You can't return arrays in C or C++. Nor can you copy arrays using assignment [edit]use strcpy to copy strings[/edit]. Is there some reason you aren't using [B]std::string[/B]? | |
Re: [QUOTE=fiza]thnks jenny for your questions, and for those who posted the solution, thank you very much, u help me a lot :))[/QUOTE]Please don't resurrect dead threads. | |
Re: [url]http://www.daniweb.com/code/search.php?query=fahrenheit[/url]? | |
Re: [QUOTE=Micko]I've been reading Narue's Timesaving Tips and found this code from Dave Sinkula [code]for (it = v.begin(); it < end; ++it)[/code][/QUOTE]Oops. [Damn copy/paste coding habits.] Thanks for spotting that -- I'll fix that post. | |
Re: As posted, I couldn't compile it. You seem to have misplaced several semicolons. [code] while ([COLOR=Magenta](calcdif >(-100)) || (calcdif >100)[/COLOR])[COLOR=Red];[/COLOR] { if (calcdif < (-100))[COLOR=Red];[/COLOR] { est = est - adj; adj = adj / 2; } else if (calcdif > 100)[COLOR=Red];[/COLOR] { est = est + adj; adj = … | |
Re: [QUOTE=sunnypalsingh][code] system("pause");[/code][/QUOTE]Don't step backwards from correct and portable code to something that isn't. (And you forgot to #include the header that declares system() as well.) | |
Re: A do...while looks like this:[code]do { /* do stuff */ } while ( /* your condition */ );[/code]And the semicolon at the end is important. | |
Re: Sounds [url=http://cboard.cprogramming.com/showthread.php?p=502033#post502033]familiar[/url]. | |
Re: Should I make up my own clockType, or do you have that too? | |
Re: [url=http://www.daniweb.com/techtalkforums/announcement8-2.html]Announcement[/url] | |
Re: [QUOTE=calcop]... and I get the following error: warning: pointer targets in passing argument 3 of 'accept' differ in signedness. sockfd was declared as an "int." cli_addr was declared as "struct sockaddr_in cli_addr;" clilen was delcared as "clilen = sizeof(cli_addr);"[/QUOTE]What is the type of [B]clilen[/B]? From the man pages I've quickly … |
The End.