2,827 Posted Topics

Member Avatar for sonygamer

[QUOTE=sonygamer;536272]I'm trying to use the switch function to compute the resistance of resistors. Basically, a person types in 3 letters, each representing a color; each color has a different value. Then v throws back the resistance by going through the equation. This is what I have so far. [code=c++] #include …

Member Avatar for Narue
0
1K
Member Avatar for wingwarp

You should start a new thread. This one's a year and a half old. Also, remember the "Keep it on the site" rule. Post your question and have people comment on it in a public thread rather than e-mail your private e-mail address.

Member Avatar for VernonDozier
0
311
Member Avatar for mistercow.pnoy

I imagine you'll be using the mod operator ( % ) in your "if" statement. As in, given an integer m and a smaller integer n, if m % n is 0, then n is a factor of m. In C++, that would be something like this: [code=C++] if (m …

Member Avatar for Nemoticchigga
0
121
Member Avatar for Jboy05

You have two separate pieces of code. Which one are you asking about? This one? [code] a = (a + b) % 2; b = b – a; a = a * b; [/code] or this one? [code] a = a + b; b = a – b; a = …

Member Avatar for VernonDozier
0
79
Member Avatar for SurviBee

I experimented with your code and I think a problem might be that you are declaring, but possibly not setting aside memory for [code] float* planA; float* planB; [/code] When I put these two lines at the top of the function: [code=C++] planA = new float; planB = new float; …

Member Avatar for VernonDozier
0
114
Member Avatar for Roebuc

I imagine it is this line that is giving you trouble: [code=C++] infile.open("C:\Users\***\Desktop\School\chapter5.txt"); [/code] It's looking for a directory called "***" under C:\Users, which I imagine does not exist. I would replace *** with the user's name. Or it is possibly seeing the backslash as an escape character? Maybe try …

Member Avatar for Roebuc
0
251
Member Avatar for jaggesh
Member Avatar for k2k

How about if you create a function that takes a large string (i.e. the user inputted sentence string named "line") and returns a vector of smaller strings? Each string in the vector would be a word. Something like this: [code=C++] vector <string> ParseIntoWords (string sentence); [/code] So in your example, …

Member Avatar for WaltP
0
359
Member Avatar for DJPlayer

This line here has an error in it: [code=C++] while ((a.get_x() 0 || (p.get_y() < 0)) [/code] The first half of the OR condition is this: [code]a.get_x() 0[/code]. I assume you want a comparison operator before the 0 such as =, <, >, etc. You are also returning 1 instead …

Member Avatar for Duoas
-1
107
Member Avatar for wollacott

You are never initializing variable pay_type_1, which is your while loop control variable, so its value is whatever happens to be there from the last time that address was used. If that value happens to be zero or negative, you will never go through that while loop.

Member Avatar for ithelp
0
107
Member Avatar for c++noobie

These lines (99 - 101) as well as others look illegal to me: [code=C++] temp.book1[a]->name = (book1+a)->name; temp.book1[a]->address = (book1+a)->address; temp.book1[a]->number = (book1+a)->number; [/code] temp is of type address_book. address_book has a data member called book1, whose type is "pointer to addBook". I do not understand what you are referring …

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

I think you have a decent start. There are links on this site that discuss some of the potential perils of using the loop control style that you used (using "eof") that you may want to look at. [code=C++] while(!inFile.eof()) { } [/code] Here is one of them. There are …

Member Avatar for VernonDozier
0
1K
Member Avatar for nurulshidanoni
Re: exam

It's a little easier to read when you put it in C++ format with C++ code tags since a lot of lines overflow. Put "code=C++" in the first bracket rather than just "code" and it gives the line numbers and makes the comments green. I'm not sure what you are …

Member Avatar for nurulshidanoni
0
121
Member Avatar for Ashu@sym

I got the same messages as you did when I tried to compile. It compiled and ran for me when I took the "char c" declaration outside of the while loop, like this: [code=C++] char c; while((c = cin.get()) != 'q') [/code] Possible the problem is that when c is …

Member Avatar for vijayan121
0
162
Member Avatar for Tommms

How about setting up a counter, initialize the counter to 0, then using a while loop? Each pass through the while loop could calculate the integer mod 10. If that result is 2 (or whatever digit you're counting), increment the counter. If not, don't increment the counter. Regardless, divide the …

Member Avatar for rhish.franks
0
219
Member Avatar for glendavis

How about changing the function to take three arguments? In addition to the two arguments you already have (pointer to the beginning of the array and the size of the array), include a third argument: firstElementNotTested. The original call would have firstElementNotTested equal to 0, since no elements would have …

Member Avatar for VernonDozier
0
175
Member Avatar for Gopala Krishnan

There is nothing wrong with the original input loop. These are words/strings that the user is inputting, not integers or something like that, where a nested input loop would be required. If the array is supposed to be 20 x 20 like you mentioned in your example, you don't need …

Member Avatar for VernonDozier
0
103
Member Avatar for peteefb

I believe possibly that the problem is in this line: [code=C] while (difference >= (1 * (10 ^ -4))); [/code] The carrot operator (^) here is interpreted not as raising 10 to the -4 power. Rather it is interpreted as doing a bitwise XOR on the numbers 10 and -4. …

Member Avatar for Ancient Dragon
0
147
Member Avatar for mrjoli021

Lemme see if I understand this. You have a program in a .cpp file and you want to create the .exe file from it? You obviously can't run/debug a project until you've built/compiled your project. You may have already tried this but have you clicked on the "Build Solution" option …

Member Avatar for VernonDozier
0
87
Member Avatar for tootypegs

Flipping the bits and adding 1 has to do with the 2's complement representation of integers. +174792 is this in 32 bit hexadecimal: 00 02 AA C8 You want negative -17492 so flipping the bits yields this: FF FD 55 37 In 2's complement, after you flip the bits you …

Member Avatar for tootypegs
0
139
Member Avatar for robotnixon

You only have one data member in the Car class, right? That variable is called "RaceCarStatus" and it is a boolean type? RaceCarStatus is true if it is a race car and false otherwise, correct? As far as I can tell there is no data member called "i". You use …

Member Avatar for John A
0
111
Member Avatar for Metalsiege

It looks like you are using the assignment operator (=) in the if statements rather than the comparison for equality operator (==): [code] if (Assignment = A) [/code] Also it appears that you are treating charaters as integers: [code] if (Assignment = A) [/code] rather than [code] if (Assignment == …

Member Avatar for Metalsiege
0
267
Member Avatar for MikeKristal

Worked for me too. For the heck of it, maybe change: [code] double taxes = 0; [/code] to [code] double taxes = 0.0; [/code] Worked fine for me with the former, but the latter is probably better. Also see this for "void main ()". [url]http://www.daniweb.com/forums/thread61091.html[/url]

Member Avatar for MikeKristal
0
111
Member Avatar for andyg55

[QUOTE=chandra.rajat;527102]Inside the Inner Loop [CODE]for (i=0; i < 3; i++){ for (j = 0; j < 3; j++) { inFile >> matrix[i][j]; printf("\n%f\t%f\t%f", matrix[i][j]); } }[/CODE] like this..[/QUOTE] You changed the printf line from the original Andy. Above is chandra.rajat's revised code based on your revised code. Here was your …

Member Avatar for VernonDozier
0
175
Member Avatar for tones1986

You already have getDepartment and getSalary accessor functions. Write accessor functions getLastName and getFirstName. They'll be almost identical to getDepartment. [code] class Employee { private: char firstName[11]; char lastName[16]; char department[16]; double salary; public: Employee(); char *getDepartment(); char* getLastName (); // add this function. char* getFirstName (); // add this …

Member Avatar for vmanes
0
208
Member Avatar for rafikul

Yes that is the problem. Try replacing "%d" with "%f". "%d" expects an integer. Also, 6 is not a float. Might want to change that to 6.0.

Member Avatar for VernonDozier
0
100
Member Avatar for tedobg

It works. I don't see the line he suggested in your code, so I don't know where you put it. The only change I'd make to carnage's advice is to put that line BEFORE the first getline, not after. You almost certainly have something "left over" in your cin input …

Member Avatar for carnage
0
107
Member Avatar for gallantmon1

Well as far as I can tell you are using the variable x but never initializing it and never changing it so it's functioning more like a constant with unknown value. You are reading data into a[x], but making "if" statements having to do with a[0]. Perhaps x is equal …

Member Avatar for gallantmon1
0
116
Member Avatar for andyg55

I'd go with the "if" statements. I like Ancient Dragon's solution and it's more efficient, but since it's new to you it may be a little confusing when you're reading it later. The "if" strategy is going to be clearer since it's familiar. Something like this: [code] if (matrix[i][3] == …

Member Avatar for VernonDozier
0
295
Member Avatar for neknek

[code] case 1: printf("Choose a column"); scanf("%c",&s); {int v; for(v=0;v<20;v++) if(s[v]='A'||s[v]='B'||s[v]='C'||s[v]='D') s[v]='*'} printf("%s",s)break; case 2: printf("Choose a column"); scanf("%c",&s); int v; for(v=0;v<20;v++) if(s[v]='A'||s[v]='B'||s[v]='C'||s[v]='D') s[v]='*'} printf("%s",s) break; case 3: printf("Choose a column"); scanf("%c",&s); int v; for(v=0;v<20;v++) if(s[v]='A'||s[v]='B'||s[v]='C'||s[v]='D') s[v]='*'} printf("%s",s) break; case 4: printf("Choose a column"); scanf("%c",&s); int v; for(v=0;v<20;v++) if(s[v]='A'||s[v]='B'||s[v]='C'||s[v]='D') s[v]='*'} …

Member Avatar for neknek
0
116
Member Avatar for chocl8drop

You're adding up to one more than the number of times through the loop because you are initializing heads, which is the number of times you get a heads, to 1 rather than 0 in the beginning with this line: [code] heads = 1; [/code] You are comparing "toss", the …

Member Avatar for chocl8drop
0
616
Member Avatar for CoolGamer48

There is the vector class. There's also a queue and/or a linked list. All of those can expand and shrink as needed. [url]http://www.cplusplus.com/reference/stl/vector/[/url] [url]http://www.cplusplus.com/reference/stl/queue/[/url] [url]http://www.cplusplus.com/reference/stl/deque/[/url]

Member Avatar for VernonDozier
0
128
Member Avatar for woozyking

[QUOTE=woozy;523953]Say I have an infinite loop, and I want to start over or terminate depending on what user inputs. [CODE] while( 1 ) // start the inifite loop { printf( "Enter your number: " ); // prompt scanf( "%d", &operand1 ); // store user entered number into operand1 if ( …

Member Avatar for invisal
0
94
Member Avatar for free2rhyme2k

english1 and english2 don't appear to be initialized. Also, in this line: [code] while((answer != english1) || (answer != english2)) [/code] you are comparing answer to the [U][B]addresses[/B][/U], not the [B][U]contents[/U][/B] of the variables english1 and english2. String comparisons don't work the way integer comparisons do. Instead of using == …

Member Avatar for neosomosis
0
124
Member Avatar for wollacott

I replaced the commas in line 34 with plus signs and it seemed to work: [code] decimal_value= value_1 + value_2 + value_3 + value_4,value_5,value_6,value_7; [/code]

Member Avatar for VernonDozier
0
140
Member Avatar for wollacott

There is no pow (int, int) function. You have to write your own. [url]http://www.cplusplus.com/reference/clibrary/cmath/pow.html[/url] As for the printf warning, I don't see that in your code, so I can't comment.

Member Avatar for WaltP
0
297
Member Avatar for andyg55

Hmm. I thought I had posted a few minutes ago, but I don't see it. I'll post again. You have a mix of doubles and integers, so the 2-D array from the last problem will no longer do the job. I'd create a struct of three integers and two doubles …

Member Avatar for VernonDozier
0
234
Member Avatar for DoctorBob

I think your algorithm has some problems. In this line: [code] while(n != 0) [/code] you are already deciding how many times you are going through the loop. n has been passed to div. So if n was 5, you're going to go through the loop 5 times? Not true. …

Member Avatar for Colin Mac
0
99
Member Avatar for twoheadedboy

[code=C++] double trap (int n, double a, double b) //Function 2 Calculation of the areas of the strips, called trap { double d, h=0, area; d=(b-a)/n; //d=Strip Width, "a" and "b" are the upper and lower bounds of the integral for (int i=1; i<=(n-1); i++) // changed commas to semicolons …

Member Avatar for VernonDozier
0
149
Member Avatar for xeption12

Not sure if this defeats the purpose of your program (it's not recursive), but for a problem with numbers as small as this, where everything is natural numbers and less than 100, you could change the equation to: y = 100 - 3x - 4xz and do a brute force …

Member Avatar for xeption12
0
131
Member Avatar for achillez

He added those compile tags to list the warnings. Without them it compiles, but doesn't list them. He has a good point about "abt", "tat", etc. when he listed the link. It's hard to take your question seriously when you write like that.

Member Avatar for Belrog
0
143
Member Avatar for mark192

[QUOTE=mark192;522008]also say i wanted to list several numbers in one if statement how would i do that? [code]If (x != 1, 2, 3, 4)[/code] Doesn't seem to be working[/QUOTE] && means "and". || means "or". Try this: [code] if (x != 1 && x != 2 && x != 3 …

Member Avatar for hsram
0
114
Member Avatar for coolbreeze

[QUOTE=coolbreeze;521013] [code] int n, sum; int total=0; [/code] [/QUOTE] Make sure you initialize the variable sum to 0 here too because you are using it later here without initializing it: [QUOTE=coolbreeze;521013] [code] sum += i; [/code] [/QUOTE] You want to use && for "AND", not a semicolon below: [QUOTE=coolbreeze;521013] [code] …

Member Avatar for vmanes
0
161
Member Avatar for gcardonav

You can change your getline in the second program to this: [code] getline(myfile, msg, '\n'); [/code] I'm assuming you want the whole line of input till the newline character? Wasn't sure what the 40 represented so I ignored it.

Member Avatar for Duoas
0
127
Member Avatar for shadowfire36

[QUOTE=chandra.rajat;519576][CODE] char line1; int line2a, line2b; char val1[4],val2[4]; char delim = ' '; indata>>line1; cout << " The ASCII value of your character is " << (char)line1 << endl; ; indata.getline(val1,4,delim); line2a = atoi(val1); indata.getline(val2,4,delim); line2b = atoi(val2); [/CODE] [/QUOTE] You're making this way too complicated. Just do this: [code] …

Member Avatar for VernonDozier
0
335
Member Avatar for kadajett

You have "name" declared as a char, so it can only hold one character. You can change name to a string or a char* and it'll be able to hold more.

Member Avatar for brk235
0
102
Member Avatar for USUAggie

Well when you are inside this loop, [code=C++] while(!realEstate.eof()){ cout << "I am here!3" << endl; //just used for debugging if(!RecordToRead.deleted){ //if file is not deleted, procede numberOfClients++; feeTemp =(RecordToRead.agentFee * RecordToRead.purchasePrice); feeTotal = feeTotal + feeTemp; } } [/code] you are not ever reading anything from the fstream "realEstate". …

Member Avatar for VernonDozier
0
79
Member Avatar for k2k

I think just replace this: [code=C++] for(int i=0; i<20; i++) { cin>>fileName[i] if(fileName[i]=='\n'; { break; } } [/code] with this: [code=C++] cin.getline (fileName, 20, '\n'); [/code]

Member Avatar for VernonDozier
0
72
Member Avatar for george45

[QUOTE=george45;520216] Output from my program 0) 0.162537 1) -0.0823975 <--Value out of range of [0.5, -0.5] 2) 0.0454712 <--Value out of range of [0.5, -0.5] 3) 0.226471 4) 0.258606 5) 0.129608 6) 0.035675 <--Value out of range of [0.5, -0.5] 7) -0.00393677 <--Value out of range of [0.5, -0.5] 8) …

Member Avatar for VernonDozier
0
166
Member Avatar for andyg55

Just commented on the other thread. Might answer your question from over here.

Member Avatar for VernonDozier
0
166

The End.