2,384 Posted Topics
Re: The error is correct -- you can't do that in todays C++. Have you been introduced to [FONT=Courier New]new[/FONT]/[FONT=Courier New]delete[/FONT]? | |
Re: [QUOTE=trevs234]in a book there is a code that i am trying out and my compiler keeps giving me diferent errors (compiler is Borland C++) and i dont know how to fix them.[/QUOTE]You may also want to post the errors. | |
Re: [Code]int Add (int [COLOR=Blue]x[/COLOR], int [COLOR=Blue]y[/COLOR]) { using std::cout; //Parameters x and y? cout << "In Add(), received " << x << " and " << y << " \n"; return (x+y) }[/Code]The function [FONT=Courier New]Add[/FONT] takes two parameters, [FONT=Courier New]x[/FONT] and [FONT=Courier New]y[/FONT]. | |
Re: >im using GCC under linux. Not my area, but I believe [FONT=Courier New][COLOR=Blue]ncurses[/COLOR][/FONT] is a good term to feed Google. | |
Re: You may want to make your tables -- and [I]dummy[/I] input --have [FONT=Courier New]int[/FONT] type. A character [FONT=Courier New]0[/FONT] ([FONT=Courier New]'\0'[/FONT]) is not the same as [FONT=Courier New]'0'[/FONT]. Either that, or use [FONT=Courier New]'0'[/FONT] and [FONT=Courier New]'1'[/FONT] in the [FONT=Courier New]char[/FONT] table. | |
Re: You're actually entering the [FONT=Courier New]%[/FONT] character, aren't you? If so, you'll need to use more complicated input handling, because the [FONT=Courier New]%[/FONT] character is not a valid character in a floating point representation; or else consider entering a fraction such as [FONT=Courier New]0.1[/FONT]. | |
Re: [QUOTE=shonenhype]I need to write a program that displays all perfect integers up to 100. I am required to write a boolean function, IsPerfect(), to use in the program.[/QUOTE]A definition of perfect numbers: a number whose value is the sum of its divisors. [QUOTE=shonenhype]Its not that Im asking for the code … | |
Re: [QUOTE=kloony]I did try the free(q), but was surprised when the following thing happened: when there were still items on my queue, i did a free(q) and then tried to access items on my queue, it turns out that the first remaining item was not accessible but the 2nd, 3rd item … | |
Re: One thing I see right away:[code] fscanf(cities, "%s \t %s \t %d\n", new_node->city1, new_node->city2, [COLOR=Blue][B]&[/B][/COLOR]new_node->distance);[/code] | |
Re: [QUOTE=arikeri]I not able to decide how to read in a data of the following table[/QUOTE]Are you saying that the following is in a text file? [code]A B(initial values) | x = 0 | x = 1 ------+--------+-------- 0 0 | q=0, y=0 | q=3, y=1 note: q=0 means A and … | |
Re: [QUOTE=arikeri]what is an arrray of fuction pointers?? Plz explain.[/QUOTE]Not the easiest thing to explain, sometimes.[code]#include <stdio.h> int foo(void) { return 1; } int bar(void) { return 2; } int baz(void) { return 3; } int main() { int (*[COLOR=Blue]afp[/COLOR][])(void) = { foo, bar, baz }; int i; for (i = … | |
Re: [code]#include <iostream> using namespace std; int main() { // your code here return 0; }[/code]And read the [url=http://www.daniweb.com/techtalkforums/announcement.php?f=8&announcementid=2]Announcement[/url]. | |
Re: [code]int a, b, c, area, tri_area; [COLOR=Red]// computer reads your mind to find out what values a, b, and c should have[/COLOR] area = tri_area(a, b, c);[/code]Plus much, much more. Do you have a specific question? | |
Re: Each nibble takes up 4 bits. So shifting by 4 times the desired position would get you to the desired spot.[code]#include <stdio.h> unsigned int set(unsigned char nibble, int pos) { return nibble << ( pos * 4 ); } unsigned char get(unsigned int value, int pos) { return ( value … | |
Re: [quote]any help in understanding this would be a great help[/quote]It means you are telling the compiler, "these functions will be available" -- to keep her quiet for compiling -- and then not telling the linker where to find them (or simply withholding them from her). You are teasing the baby, … | |
Re: Why not post the code of how you'd do it with a [FONT=Courier New]while[/FONT] loop? Then maybe your best attempt at converting it to a [FONT=Courier New]for[/FONT] loop? | |
Re: Code tags will preserve the spacing.[QUOTE=tenoran]Thanks for trying. But my queestion was little bit unclear. I will put the txt file and out put that I get so far.[code] txt file out put 1234 052 007 100 078 034 Id Quiz1 Quiz2 Quiz3 Quiz4 Exam 2134 090 036 090 077 … | |
Re: [quote]Warning W8013 line 55: Possible use of 'x2' before definition in function main() Warning W8013 line 55: Possible use of 'y2' before definition in function main() [/quote]Perhaps you want to pass [I]by reference[/I] to [FONT=Courier New]magnitude[/FONT]?[quote]Error: Unresolved external 'report1(double, int)' Error: Unresolved external 'report2(double, int, double)' [/quote]And maybe make the … | |
Re: >Do you need to put the ; after the last }? No. >Do you need to put a return statement before the last }? No, but it's a good idea. >If so, what number do you put in the (), i.e. return (0), return (1), etc. Use [FONT=Courier New]0[/FONT], [FONT=Courier … | |
Re: Do you know [U]why[/U] some [FONT=Courier New]fopen[/FONT] call failed? Using [FONT=Courier New]perror[/FONT] might give a better error message, like "no such file or directory", "permission denied", or "too many open files". But sure, you could also do something like this.[code]puts(strerror(errno));[/code] | |
Re: > I am using the closing tag.. I swear. > this is code between the tags | |
Re: [QUOTE=Tight_Coder_Ex][COLOR=Red]single[/COLOR], double, float, int, short, long are all type specifiers so in the example[/QUOTE]For what language(s) is single a type? | |
Re: [QUOTE=BountyX]read [url="http://homepages.tesco.net/~J.deBoynePollard/FGA/legality-of-void-main.html"]http://homepages.tesco.net/~J.deBoynePollard/FGA/legality-of-void-main.html[/url] Unfortunetly there is a valid claim to using void main(). It's bad practice, but does; technically, follow the standard (the specific standard mentioned in that article).[/QUOTE]Been there, done that. I like [url=http://www.research.att.com/~bs/bs_faq2.html#void-main]this[/url]: [quote]Even if your compiler accepts "void main()" avoid it, or risk being considered ignorant by C … | |
Re: [FONT=Courier New]structname[/FONT] is the type. So what the compiler is telling you is that you are trying to do something akin to [FONT=Courier New][COLOR=Indigo]int = 5[/COLOR][/FONT]. You want to assign to a member of the object pointed to:[code]#include <iostream> using namespace std; struct structname { int i; }; int main(void) … | |
Re: [code] i<=J&&j<=i?cout<<"i and j equal":cout<<"i and j not equal";cout<<endl; //output 4[/code]Doesn't your compiler say something like this?[quote][FONT=Fixedsys]Undefined symbol 'J' in function main()[/FONT][/quote]Which would make it easy to find this:[code] i<=[COLOR=Red][B]J[/B][/COLOR]&&j<=i?cout<<"i and j equal":cout<<"i and j not equal";cout<<endl; //output 4[/code] | |
Re: It seems like your highlighted text would make some good Googling. STFW first. Follow up here to try to get questions to specific problems related to whichever language you choose. | |
Re: [code]void getDrawers(int &numDrawers) { cout <<"Enter the number of drawers you would like."<<endl; cin >> numDrawers; } int main() { int numDrawers; getDrawers(numDrawers); // ...[/code] | |
Re: Aaaaaah![code]main() clrscr(); printf("\n\t\t\t Enter roll number: "); scanf("%d",&tempdata.rollno); fflush(stdin); printf("\n\t\t\t Enter Name: "); gets(tempdata.name); fflush(stdin); printf("\n\t\t\t Enter Topic: "); gets(tempdata.topic); getch();[/code]Burn the book (or teacher) you have been learning from. [U]gets()[/U][list][*][url]http://www.eskimo.com/~scs/C-faq/q12.23.html[/url] [*][url]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1044652485&id=1043284385[/url] [*][url=http://www.rsasecurity.com/rsalabs/technotes/buffer/buffer_overflow.html]buffer overflow[/url][/list] [U]fflush(stdin)[/U][list][*][url]http://www.eskimo.com/~scs/C-faq/q12.26.html[/url] [*][url]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?id=1043284392&answer=1044873249[/url] [*][URL]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1052863818&id=1043284351[/URL][/list] [U]scanf()[/U][list][*][url]http://www.eskimo.com/~scs/C-faq/q12.20.html[/url] [*][url]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1044652485&id=1043284385[/url][/list] [U]clrscr()[/U][list][*][url]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1031963460&id=1043284385[/url] [*][url]http://www.eskimo.com/~scs/c-faq/q19.4.html[/url][/list] You're not quite there, but let's nip this in … | |
Re: Prototypes tell you the expected types, but when you call a function you don't include the type -- the type is inherently part of the variable or literal being used in the call. That is,[code]if (GetKeyState(48)==1){[/code] | |
Re: [QUOTE=mariners95]Could someone help me with a linked list code. I just cant figure it out. I dont know how to code the part where I need to insert an element in ascending order. Either when there are no nodes then when there is one or a few nodes. Can anyone … | |
Re: [QUOTE=Ian13]Can anyone help me with getting past this? I want it to be where you can enter another country other than the one you just looked at and it will display the data for that country too. I think that it might have something to do with variables and looping? … | |
Re: [url]http://www.compilers.net/Dir/Free/Compilers/CCpp.htm[/url] [url=http://www.bloodshed.net/]Dev-C++[/url] is frequently mentioned. | |
Re: Equivalent loops:[code] [B][COLOR=blue]int[/COLOR][/B] i; [COLOR=chocolate]/* * #1: while */[/COLOR] i = [COLOR=teal]0[/COLOR]; [B][COLOR=blue]while[/COLOR][/B] ( i < [COLOR=teal]10[/COLOR] ) { [COLOR=chocolate]// ...[/COLOR] ++i; } [COLOR=chocolate]/* * #2: do...while */[/COLOR] i = [COLOR=teal]0[/COLOR]; [B][COLOR=blue]do[/COLOR][/B] { [COLOR=chocolate]// ...[/COLOR] ++i; } [B][COLOR=blue]while[/COLOR][/B] ( i < [COLOR=teal]10[/COLOR] ); [COLOR=chocolate]/* * #3: for */[/COLOR] [B][COLOR=blue]for[/COLOR][/B] ( … | |
Re: Something akin to this?[code]#include <stdio.h> struct node { int i; char c; }; struct node list[] = { {1,'A'},{2,'B'},{3,'C'},{4,'D'},{5,'E'},{6,'F'},{7,'G'},{8,'H'},{9,'I'}, }; struct node *plist[] = { &list[0], &list[2], &list[4], &list[6], &list[8], &list[1], &list[3], &list[5], &list[7], }; int main(void) { size_t i; puts("list:"); for ( i = 0; i < sizeof list … | |
Re: [QUOTE=Asif_NSU]The thing is that i dont create projects to do my work.[/QUOTE]You may want to investigate makefiles. Then you can use your favorite editor and still write modular code the correct way. | |
Re: [The title does not provoke much interest or specify what you are really trying to do. Expend a little more thought for something like, "Adding and Reducing Fractions". Such things show you have thought about the problem and perhaps done some searching for related information.] With regard to reducing the … | |
Re: [url]http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.13[/url] | |
Re: This is just begging to be made into an array:[code]int sale1; int sale2; int sale3; int sale4; int sale5; int sale6; int sale7; int sale8; int sale9; int sale10; int sale11; int sale12;[/code]And please use code tags. | |
Re: cin and cout are part of the standard namespace. Early on, use this:[code]using namespace std; // after the #includes[/code]Since you[code]cin >> base_cost; [/code]you shouldn't make it [FONT=Courier New]const[/FONT].[code]float base_cost = 50.00, // base cost of rental[/code]Statements end in a semicolon.[code]rental_cost = base_cost + (cost_daily * n_days)[COLOR=Blue];[/COLOR] tax = rental_cost * … | |
Re: Have you looked in the [url=http://www.daniweb.com/code/code-c.html]code snippets[/url]? | |
Re: [url]http://www.catb.org/~esr/faqs/smart-questions.html[/url] | |
Re: Here's a truth table: [url]http://www.ii.uam.es/~jlara/investigacion/ecomm/electronica/2adder.html[/url] | |
Re: If x is 1, it won't be 2 or 3.[CODE]if (x == 1) { statement1 } else if (x == 2) { statement2 } else if (x == 3) { statement3 } else { statement4 }[/CODE] | |
Re: [QUOTE=cymbalistic1]I just need somebody to tell me how to export the data into Excel.[/QUOTE]Write it to a .txt file or .csv file and import it into Excel. | |
Re: [QUOTE=evilsilver]yes you can asign them with =, try this[code]char *test = new char [100]; test = "this works"; [/code][/QUOTE]That's not assigning a [I]string[/I]. That's assigning a pointer (and a memory leak). | |
Re: I think something like this may help.[code] if (choice == "b" || choice == "B") { cout << "Checking Balance: $" << setw(8) << setprecision(2) << fixed << checking << '\n'; cout << "Savings Balance: $" << setw(8) << setprecision(2) << fixed << savings << endl; }[/code] | |
Re: Try adding some outputs to see what is going on. Please post a compilable sample as opposed to some fragment. | |
Re: You need to terminate the following statements with semicolons:[code]const double conversion = 2.54[COLOR=Blue];[/COLOR] const int inchesPerFoot = 12[COLOR=Blue];[/COLOR][/code]And this was okay many years ago...[code]#include <iostream.h>[/code]...but if you are living in the 21st century, it should be...[code]#include <iostream>[/code]...especially since you are...[code]using namespace std;[/code] |
The End.