2,384 Posted Topics

Member Avatar for gracieLou

You may want to look up [FONT=Courier New]strtod[/FONT] or [FONT=Courier New]strto[u]l[/FONT]. If you are trying to use these C-style functions with a [FONT=Courier New]std::string[/FONT], look at the [FONT=Courier New]c_str()[/FONT] member function too.

Member Avatar for marinme
0
95
Member Avatar for cblue
Member Avatar for Narue
0
157
Member Avatar for JoBe

I was under the impression that the return value might be expected to be an [FONT=Courier New]unsigned int[/FONT], and that the expected input/output might be as follows.[code]#include <stdio.h> unsigned int dec2bcd(unsigned int dec) { unsigned int bits, bcd = 0; for ( bits = 0; dec; bits += 4, dec …

Member Avatar for Narue
0
604
Member Avatar for dal4488

Which seems to make more sense? Try them side by side.[quote]To avoid an infinite loop make sure the loop body alters the exit condition. To avoid an infinite loop make sure the loop body contains at least one output statement.[/quote]Would altering the loop exit condition affect looping? Or would an …

Member Avatar for thedk
0
109
Member Avatar for rharvison

Oh, my.[code]outfile << setiosflags(ios::showpoint|ios::fixed)<< setprecision(2); outfile << setw(49)[color=blue]<<[/color]"Mini Computer" << endl; outfile << setw(49)[color=blue]<<[/color]"=============" << endl << endl; outfile << setw(35)[color=blue]<<[/color]"Operand 1" [color=blue]<<[/color]setw(35)[color=blue]<<[/color]"Operand 2" [color=blue]<<[/color]endl; outfile << setw(35)[color=blue]<<[/color]"=========" [color=blue]<<[/color]setw(35)[color=blue]<<[/color]"=========" [color=blue]<<[/color]endl << endl; outfile << setw(35)[color=blue]<<[/color]op1 << setw(35)[color=blue]<<[/color]op2 << endl << endl; outfile << setw(8)[color=blue]<<[/color]"Sum" [color=blue]<<[/color]setw(15)[color=blue]<<[/color]"Difference" [color=blue]<<[/color]setw(12)[color=blue]<<[/color]"Product" [color=blue]<<[/color]setw(19)[color=blue]<<[/color]"Whole Quotient" [color=blue]<<[/color]setw(14)[color=blue]<<[/color]"Remainder" [color=blue]<<[/color]endl; …

Member Avatar for rharvison
0
115
Member Avatar for solthirsty

Here is one example of a dynamic array inside a class.[code]#include <iostream> class T { int size, *array; public: T(int mysize = 1) : size(mysize), array(new int[size]) { std::cout << "size = " << size << '\n'; } ~T() { delete[] array; } }; int main() { T a, b(5); …

Member Avatar for Dave Sinkula
0
178
Member Avatar for mikecoyner

Perhaps [FONT=Courier New]cin.ignore[/FONT] the newline following the [FONT=Fixedsys]Enter q to quit[/FONT] prompt. And probably after the GPA, too.

Member Avatar for mikecoyner
0
258
Member Avatar for koolguysj

I might choose this for overflow checking.[code] if ( *nfact > INT_MAX / count )[/code]I've also discarded [FONT=Courier New]result[/FONT] and used [FONT=Courier New]*nfact[/FONT] in its place.

Member Avatar for Dave Sinkula
0
128
Member Avatar for dal4488

>I'm not really sure what to do? First, read from the file, not [FONT=Courier New]cin[/FONT]. Next, if your file has an [FONT=Courier New]f[/FONT] or [FONT=Courier New]m[/FONT] preceding the GPA, you'll need to read this character. Then, depending on which it was, you'd adjust one of the two running sums.

Member Avatar for Dave Sinkula
0
183
Member Avatar for Auto

[code]strcpy(set1[i].status,datalist[random_number]);[/code]not[code]strcpy(set1[i].status,[COLOR=Red]&[/COLOR]datalist[random_number][COLOR=Red][20][/COLOR]);[/code]

Member Avatar for Auto
0
155
Member Avatar for rpgplyrff8

Make sure your function's prototype matches its definition.[code]int s ([COLOR=Blue]void[/COLOR])[/code]

Member Avatar for Dave Sinkula
0
145
Member Avatar for duner

Sometimes you just have to look at something for a while before it [I]clicks[/I]. Adding extra [FONT=Courier New]printf[/FONT] statments can sometimes help to see what is going on. [code]#include <stdio.h> int main(void) { int i, array[10]; for ( i = 0; i < 10; ++i ) { array[i] = i; …

Member Avatar for duner
0
2K
Member Avatar for Acidburn

A [FONT=Courier New]Student[/FONT] needs to know what a [FONT=Courier New]Date[/FONT] is. Perhaps put the inclusion of [FONT=Courier New]"date.h"[/FONT] into [FONT=Courier New]"student.h"[/FONT], or change the order of inclusion in your module.

Member Avatar for Dave Sinkula
0
270
Member Avatar for hasan2003
Member Avatar for JoBe

1) Do you understand what the idea is for this exercise when reading the task? 2) If so, could you give an example of what is meant by it? Isn't it asking to do something like this? unsigned int datecode (int year, int month, int day) { if ( year …

Member Avatar for Narue
0
402
Member Avatar for Mature_Student

[QUOTE=Mature_Student]I need to write a function that takes a time in seconds and returns a formatted string (hh:mm:ss) [/QUOTE]Shouldn't it look more like this, then?[code]string FormatTime(int ts) { string result; // ... return result; }[/code]And used like this?[code]string formattedTime = FormatTime(totalSeconds);[/code]

Member Avatar for Mature_Student
0
227
Member Avatar for Auto

For starters, I'd recommend putting the following into a header, say [FONT=Courier New]"tables.h"[/FONT].[code]struct employee { char name[20]; int schedule; int level; }; [COLOR=Blue]extern[/COLOR] struct employee salesdept[10];[/code]Then in [FONT=Courier New]"tables.cpp"[/FONT] have this.[code][COLOR=Blue]#include "tables.h"[/COLOR] int show_employee_data(void) { struct employee *ptr_sales; ptr_sales=&salesdept[0]; for(int i=0; i<10; i++) { printf("Employee: %s\n",ptr_sales->name); printf("Shift: %d\n",ptr->schedule); printf("Level: %d\n\n\n",ptr->level); …

Member Avatar for Auto
0
242
Member Avatar for Acidburn

Should it be like this?[code]debug::debug([COLOR=Blue]int[/COLOR] a) { [COLOR=Magenta]x[/COLOR] = [COLOR=Magenta]a[/COLOR]; }[/code]

Member Avatar for Dave Sinkula
0
573
Member Avatar for Fasola

[QUOTE=Fasola]I know about double arrays but haven't heard of a triple array It maybe a stupid question, but do they exist? could you have this type of an array???:[/QUOTE]Yes you can.

Member Avatar for Fasola
0
310
Member Avatar for JoBe

[QUOTE=JoBe]Problem is, when I run threw the loop in the function and arrive at the fourth digit '4', the compiler changes the number into '39997' and I get a wrong result :o [/QUOTE]Floating point behaves this way because the value stored is an approximation. Since you're passing a [FONT=Courier New]double[/FONT], …

Member Avatar for JoBe
0
299
Member Avatar for sasha16

You use [FONT=Courier New]loanBalance[/FONT] before it is initialized: [code]monthlyIntPymt = loanBalance * monthlyInterestRate; monthlyPrincipalPymt = monthlyPaymentAmt - (loanBalance * INT_RATE); loanBalance = loanBalance - monthlyPrincipalPymt;[/code]

Member Avatar for Dave Sinkula
0
150
Member Avatar for ncat_08

Read the [URL=http://www.daniweb.com/techtalkforums/announcement.php?f=8&announcementid=2]Announcement[/URL].

Member Avatar for ncat_08
0
90
Member Avatar for baboon4000
Member Avatar for Acidburn

[code]void Student::setName(char [COLOR=Blue]*[/COLOR]N) { strcpy(student , [COLOR=Blue]N[/COLOR]); }[/code][code] cin >> student; St1.setName([COLOR=Blue]student[/COLOR]); St1.PrintName();[/code]

Member Avatar for Acidburn
0
456
Member Avatar for cblue
Member Avatar for Dave Sinkula
0
92
Member Avatar for Tink2416

This doesn't sound like a C or C++ question. You may want to try technical support for your software. [url]http://thesims.ea.com/us/support/[/url]

Member Avatar for Dave Sinkula
0
112
Member Avatar for DaveSS

[code]int number = 0; float profit[arraySize]; float hold[arraySize]; //just added[/code][code] sortIndex(profit [numberOfBoxes],hold[numberOfBoxes],number); //to sort by profit[/code][code]void sortIndex (int[], float a[], int n, int k)// int[] - a list of indexes that will be sorted with the sort values. { // float [] - the list of values to sort. // …

Member Avatar for Dave Sinkula
0
179
Member Avatar for sinB

[quote]Why does my compiler (Turbo c++ v 3) return errors?[/quote]Posting the error messages is often helpful.[code]char str_arr[[COLOR=Red]sslen[/COLOR]/2][[COLOR=Red]sslen[/COLOR]];[/code]You cannot declare an array with non-constant dimensions.

Member Avatar for Fasola
-1
411
Member Avatar for Geek-Master

It would probably be easier if you posted a real example of an if tree that you don't like.

Member Avatar for Geek-Master
0
105
Member Avatar for Tight_Coder_Ex

[QUOTE=Tight_Coder_Ex]I'd like to read a floating point value [b]cin >> Value [/b]where Value is declared as a double and then output it to a string justified to two decimal places. I understand how to do it using a temporary file, but I'd like to avoid that method and [b]sprintf() [/b]if …

Member Avatar for Tight_Coder_Ex
0
164
Member Avatar for sgbartley

[url]http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.3[/url]

Member Avatar for Narue
0
183
Member Avatar for ok555

[QUOTE=ok555]what am i doing wrong people? char name[] = "bob"; char send[512]; sprintf(send, "testing this [COLOR=Red]%d[/COLOR]\n",name);[/QUOTE]Use [FONT=Courier New]%s[/FONT] for strings; [FONT=Courier New]%d[/FONT] is for [FONT=Courier New]int[/FONT]s.

Member Avatar for ok555
1
163
Member Avatar for j.kelly

Why not put that in its own header and [FONT=Courier New]#include[/FONT] it where you need it?

Member Avatar for j.kelly
0
85
Member Avatar for arikeri

I think you need to specialize your inner sets.[code]set<set[COLOR=Blue]<int>[/COLOR] > partition(set[COLOR=Blue]<int>[/COLOR] inp);[/code]

Member Avatar for Dave Sinkula
0
231
Member Avatar for riturajraina
Member Avatar for Raven11

[QUOTE=Raven11]I'm trying to make so you have to type a character in for username [COLOR=Blue]and[/COLOR] password. If this is the case it goes the the error txt box and says so. However, it always returns false and returns the else statement true. Any advice what I'm doing wrong?[/QUOTE][code]#include <stdio.h> int …

Member Avatar for Raven11
0
165
Member Avatar for JayseR

Enclose blocks of code corresponding to an [FONT=Courier New]if[/FONT] statement within braces [FONT=Courier New]{ }[/FONT]. This[code] if(input1 > input2 && input2 > input3) cout << endl; cout << input1 << endl; cout << input2 << endl; cout << input3 << endl; [/code]means this[code] if(input1 > input2 && input2 > input3) …

Member Avatar for JayseR
0
219
Member Avatar for dello

Your nested [FONT=Courier New]for[/FONT] loops mean that you are trying to read 144 values each line. To me it looks like the [FONT=Courier New]do...while[/FONT] is attempting to be what the first [FONT=Courier New]for[/FONT] loop should be: rows. I'd do something more like this. [code] for ( int i = 0; …

Member Avatar for dello
0
227
Member Avatar for jonnie83

Do you mean concatenation? Are you using std::string or C-style strings (or other)? Can you post the code of you attempt that you are having trouble with (within CODE tags)?

Member Avatar for Dave Sinkula
0
170
Member Avatar for evilsilver

[QUOTE=evilsilver]ok i know how to use mciSendString, it is mciSendString("[play/stop] [path to file]",NULL,0,NULL); , (for audio is what i am using it for) but i don't understand what the NULL,0,NULL is for, can anyone help me? and another thing is there a way to make the file i play with …

Member Avatar for Dave Sinkula
0
214
Member Avatar for baboon4000

You can write a program that will obtain user input and then examine this text to see whether it contains duplicates. If the verification fails, you may elect to loop back and prompt for the same input again.

Member Avatar for Dave Sinkula
0
223
Member Avatar for notdumb

[QUOTE=notdumb]First, I am getting unresolved externals errors. I do not know how to find where these are in my program when I get them. So my first question is, and I am using microsoft visual C++ 6.0 as a compiler, how do I find where the unresolved externals are to …

Member Avatar for Dave Sinkula
0
138
Member Avatar for JayseR

>I am not sure how to isolate the first 4 points so I can How about changing [FONT=Courier New]getdata[/FONT] just a wee bit.[code]void getData(double& n) { if ( infile >> n ) { cout << "number = " << n << endl; } }[/code]And then in [FONT=Courier New]main[/FONT] actually passing …

Member Avatar for JayseR
0
522
Member Avatar for tyczj

As a constant? [code]#include <iostream> int main() { double value = [COLOR=Blue]1.23456E+3[/COLOR]; std::cout << "value = " << value << '\n'; return 0; } /* my output value = 1234.56 */[/code]

Member Avatar for Narue
0
170
Member Avatar for dallin

Why wouldn't you just assign the array members 1-9?[code] int i, array[9]; for (i = 0; i < 9; ++i) { array[i] = i + 1; }[/code]

Member Avatar for Narue
0
327
Member Avatar for Layla_2401

Do you have a small, but complete, example? I cannot compile the code you have posted, and this makes offering assistance much more difficult.

Member Avatar for Layla_2401
0
334
Member Avatar for asdflkjh

The prototypes end with a semicolon, the function definitions don't. The prototypes should be before main(), not between main() and its {. Make the prototypes match the definitions with respect to formal parameters. Statements end in a semicolon (in your if tree). Match all your opening braces with closing braces …

Member Avatar for Acidburn
0
236
Member Avatar for blackdove

[CODE][B][COLOR=green]#include[/COLOR][/B] <stdio.h> [B][COLOR=green]#include[/COLOR][/B] <stdlib.h> [B][COLOR=blue]int[/COLOR][/B] [B][COLOR=red]main[/COLOR][/B]([B][COLOR=blue]void[/COLOR][/B]) { [B][COLOR=blue]const[/COLOR][/B] [B][COLOR=blue]char[/COLOR][/B] text[] = [COLOR=Teal]"3E8"[/COLOR]; [B][COLOR=blue]int[/COLOR][/B] value = [B][COLOR=red]strtol[/COLOR][/B](text, [COLOR=indigo]NULL[/COLOR], [COLOR=Teal]16[/COLOR]); [B][COLOR=red]printf[/COLOR][/B]([COLOR=Teal]"%s = %d\n"[/COLOR], text, value); [B][COLOR=blue]return[/COLOR][/B] [COLOR=teal]0[/COLOR]; } [COLOR=chocolate]/* my output 3E8 = 1000 */[/COLOR][/CODE]

Member Avatar for blackdove
0
267
Member Avatar for xfruan

[QUOTE=xfruan]I'm looking for books that deal with more advanced topics and programming tips.[/QUOTE]Like...? [thread=10232]Books[/thread]

Member Avatar for xfruan
0
181
Member Avatar for bluegoo06

[QUOTE=bluegoo06]i have to define a function that tests number from 2 to 10000 to see if they are prime. [code]for (i =2; i <= [COLOR=Blue]500[/COLOR]; i++)[/code]but it only tests prime numbers until about 500 or so[/QUOTE]That's what you tell it to do. [QUOTE=bluegoo06]then it gets most of the numbers to …

Member Avatar for samarth
0
93

The End.