2,384 Posted Topics
Re: 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. | |
Re: [url]http://www.daniweb.com/code/search.php?query=decimal[/url] | |
Re: 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 … | |
Re: 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 … | |
Re: 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; … | |
Re: 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); … | |
Re: 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. | |
Re: 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. | |
Re: >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. | |
Re: [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] | |
Re: Make sure your function's prototype matches its definition.[code]int s ([COLOR=Blue]void[/COLOR])[/code] | |
Re: 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; … | |
Re: 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. | |
Re: No. It contains whatever data the array type is. | |
Re: 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 … | |
Re: [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] | |
Re: 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); … | |
Re: Should it be like this?[code]debug::debug([COLOR=Blue]int[/COLOR] a) { [COLOR=Magenta]x[/COLOR] = [COLOR=Magenta]a[/COLOR]; }[/code] | |
Re: [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. | |
Re: [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], … | |
Re: You use [FONT=Courier New]loanBalance[/FONT] before it is initialized: [code]monthlyIntPymt = loanBalance * monthlyInterestRate; monthlyPrincipalPymt = monthlyPaymentAmt - (loanBalance * INT_RATE); loanBalance = loanBalance - monthlyPrincipalPymt;[/code] | |
Re: Read the [URL=http://www.daniweb.com/techtalkforums/announcement.php?f=8&announcementid=2]Announcement[/URL]. | |
Re: Could you post [FONT=Courier New]flat.h[/FONT] as well? | |
Re: [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] | |
| |
Re: 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] | |
Re: [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. // … | |
Re: [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. | |
![]() | Re: It would probably be easier if you posted a real example of an if tree that you don't like. ![]() |
Re: [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 … | |
Re: [url]http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.3[/url] | |
Re: [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. | |
![]() | Re: Why not put that in its own header and [FONT=Courier New]#include[/FONT] it where you need it? ![]() |
Re: I think you need to specialize your inner sets.[code]set<set[COLOR=Blue]<int>[/COLOR] > partition(set[COLOR=Blue]<int>[/COLOR] inp);[/code] | |
Re: Can you dynamically allocate some of the required memory? | |
Re: [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 … | |
Re: 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) … | |
Re: 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; … | |
Re: 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)? | |
Re: [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 … | |
Re: 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. | |
Re: [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 … | |
Re: >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 … | |
Re: 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] | |
Re: 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] | |
Re: Do you have a small, but complete, example? I cannot compile the code you have posted, and this makes offering assistance much more difficult. | |
Re: 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 … | |
Re: [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] | |
Re: [QUOTE=xfruan]I'm looking for books that deal with more advanced topics and programming tips.[/QUOTE]Like...? [thread=10232]Books[/thread] | |
Re: [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 … |
The End.