2,384 Posted Topics

Member Avatar for kahaj

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 …

Member Avatar for Dave Sinkula
0
232
Member Avatar for virusm

[url]http://www.daniweb.com/techtalkforums/announcement8-2.html[/url] [url]http://www.daniweb.com/techtalkforums/faq.php?faq=daniweb_faq#faq_rules[/url]

Member Avatar for Dave Sinkula
0
78
Member Avatar for atrusmre

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.

Member Avatar for atrusmre
0
2K
Member Avatar for brian63304

A struct cannot contain an instance of itself -- perhaps you meant to have a pointer to the next instance in the Node (and elsewhere).

Member Avatar for kafkanien
0
78
Member Avatar for btech

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]

Member Avatar for Lerner
0
194
Member Avatar for smallville

[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, …

Member Avatar for Dave Sinkula
0
198
Member Avatar for jack223

You've just discovered your first reason to dislike global variables! [code]balance = (Interest + 1.0f) * [COLOR=Magenta]B[/COLOR]alance;[/code]

Member Avatar for jack223
0
132
Member Avatar for btech

[url]http://www.parashift.com/c++-faq-lite/templates.html#faq-35.16[/url]

Member Avatar for Ancient Dragon
0
162
Member Avatar for tdizzle342

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]

Member Avatar for tdizzle342
0
300
Member Avatar for wdowell84

[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 …

Member Avatar for Dave Sinkula
0
166
Member Avatar for Batman007

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 …

Member Avatar for Batman007
0
254
Member Avatar for mb1

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.

Member Avatar for Ancient Dragon
0
2K
Member Avatar for simon126

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.

Member Avatar for Dave Sinkula
0
146
Member Avatar for server_crash
Member Avatar for server_crash
0
124
Member Avatar for djjkotze

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]

Member Avatar for Dave Sinkula
0
208
Member Avatar for server_crash

[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 …

Member Avatar for server_crash
0
2K
Member Avatar for glamo
Member Avatar for EsMaru
0
168
Member Avatar for bigwillis234
Member Avatar for Rashakil Fol
0
302
Member Avatar for Acidburn

Did you type two characters -- [inlinecode]'A'[/inlinecode] and a newline? Also, [inlinecode]getchar[/inlinecode] returns an [inlinecode]int[/inlinecode].

Member Avatar for Dave Sinkula
0
112
Member Avatar for amy590

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 …

Member Avatar for amy590
0
163
Member Avatar for nabil1983
Member Avatar for LordJayno

[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 = …

Member Avatar for LordJayno
0
195
Member Avatar for Talyen42

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]

Member Avatar for Dave Sinkula
0
255
Member Avatar for mhk_mohsin

[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]?

Member Avatar for Ene Uran
0
136
Member Avatar for glamo

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.

Member Avatar for SpS
0
83
Member Avatar for glamo

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].

Member Avatar for Dave Sinkula
0
94
Member Avatar for bobobobo51

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 = …

Member Avatar for svirk
0
254
Member Avatar for Gamermonk10

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 ( …

Member Avatar for Gamermonk10
0
239
Member Avatar for imanust

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) << …

Member Avatar for winbatch
0
195
Member Avatar for simon126

[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 …

Member Avatar for simon126
0
650
Member Avatar for Savage221

Seed the random number generator only once in your program. Move your srand call to main, before your for loops.

Member Avatar for firepiro05e91
0
1K
Member Avatar for daybreak7

[url]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1045691686&id=1043284392[/url]

Member Avatar for daybreak7
0
135
Member Avatar for Acidburn

[url=http://www.daniweb.com/code/snippet406.html]Quickie concatenation algorithm[/url].

Member Avatar for Dave Sinkula
0
178
Member Avatar for lalfonsob

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 …

Member Avatar for Dave Sinkula
0
106
Member Avatar for Gamermonk10

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.]

Member Avatar for Gamermonk10
0
228
Member Avatar for PeterX

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) = …

Member Avatar for Dave Sinkula
0
176
Member Avatar for winbatch

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 …

Member Avatar for Dave Sinkula
0
2K
Member Avatar for tippytoe

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.

Member Avatar for Ene Uran
0
199
Member Avatar for shantise2003

[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.

Member Avatar for Dave Sinkula
0
108
Member Avatar for Toshkin78

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]?

Member Avatar for Toshkin78
0
1K
Member Avatar for jenyin84

[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.

Member Avatar for Dave Sinkula
0
774
Member Avatar for kahaj

[url]http://www.daniweb.com/code/search.php?query=fahrenheit[/url]?

Member Avatar for Dave Sinkula
0
133
Member Avatar for Micko

[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.

Member Avatar for Dave Sinkula
0
109
Member Avatar for kdw3

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 = …

Member Avatar for Dave Sinkula
0
155
Member Avatar for kdw3

[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.)

Member Avatar for Narue
0
602
Member Avatar for simon126

A do...while looks like this:[code]do { /* do stuff */ } while ( /* your condition */ );[/code]And the semicolon at the end is important.

Member Avatar for Lerner
0
261
Member Avatar for Ryrra

Sounds [url=http://cboard.cprogramming.com/showthread.php?p=502033#post502033]familiar[/url].

Member Avatar for Ryrra
0
119
Member Avatar for btech
Member Avatar for Dave Sinkula
0
784
Member Avatar for cobra2003

[url=http://www.daniweb.com/techtalkforums/announcement8-2.html]Announcement[/url]

Member Avatar for Dave Sinkula
0
101
Member Avatar for calcop

[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 …

Member Avatar for calcop
0
104

The End.