2,712 Posted Topics

Member Avatar for PDB1982

make a separate function. [code] bool isPrime(int i) { /* logic here */ }; //somewhere inside main if( isPrime(i) == true ) cout <<" Prime \n" ; else cout <<" not a prime\n"; [/code] Of course this code depends on isPrime function. You should try to create that on your …

Member Avatar for JasonHippy
0
99
Member Avatar for clue.less
Member Avatar for hello214

I think you want it to be this : [code] static float calcTaxes(float grossPay) { float netPay ; if (grossPay <= 300) netPay = (float) (grossPay - (grossPay * 0.15)); if (grossPay <= 450) netPay = (float)(grossPay - (grossPay * 0.20)); else if (grossPay > 450) netPay = (float)(grossPay - …

Member Avatar for hello214
0
82
Member Avatar for ENCHTERP

[code] //assume vec2d is a 2 d vector vector< data_type > copyRow( vec2d[0].begin(), vec2d[0].end()); [/code] That would copy the row 0 onto copyRow vector

Member Avatar for VernonDozier
0
8K
Member Avatar for minex

[URL="http://www.cplusplus.com/reference/iostream/stringstream/stringstream/"]http://www.cplusplus.com/reference/iostream/stringstream/stringstream/[/URL]

Member Avatar for mrnutty
0
131
Member Avatar for pocku

How about you just ask your teacher since it will be easier and more straight forward.

Member Avatar for pocku
0
188
Member Avatar for lipun4u

[QUOTE=BeyondTheEye;1014631]You might want to change your destructor. [CODE=CPP]delete [] st;[/CODE] instead of [CODE=CPP] delete st; [/CODE] You'll be creating memory leaks if you don't.[/QUOTE] Not memory leak, but undefined behavior.

Member Avatar for mrnutty
0
136
Member Avatar for ashok.g15

[quote] char arrURI[1]; -- creates an array of size one -- so there are two indexes 0 and 1 [/quote] Actually there is only 1 index, which is 0 in char A[1]; A[0] = 'a'; //ok A[1] = 'b'; //bug

Member Avatar for Tom Gunn
1
951
Member Avatar for hket89

A side note : one of the main reason call by reference was created is because passing a class object by value is expensive. You can think of Pass by reference like a pointer in disguise.

Member Avatar for BestJewSinceJC
0
175
Member Avatar for ddashtrois

You could make your code cleaner by using functions, assumming you have learned them already. Not tested. [code] #include<iostream> #include<cmath> using namespace std; bool isPrime(int i) { if(i == 2) return true; for(int j = 2; j < i; j++) //you could optimize but this is for simplicity. if( i …

Member Avatar for mrnutty
0
411
Member Avatar for hopeful man

Realize the obvious pattern first. [code] 4444**** //there are 4 4's and 4 *'s 333*** //there are 3 3's and 3 *'s 22** // and so on 1* 22** 333*** 4444**** [/code]

Member Avatar for mrnutty
0
108
Member Avatar for Phil++

[QUOTE=niek_e;1013128]Yes, but change [icode]if(c[i].GetName() = "Phil")[/icode] to [icode]if(c[i].GetName() [COLOR="Red"]==[/COLOR] "Phil")[/icode]. That should solve your compile-error :) [edit] And C has to be an array (or vector ) of classes for thiss to work![/QUOTE] Be sure use strcpy when comparing cStyle String, [code] if( strcmp( ArrayOfClasses[i].getName(), "phil") == 0 ) { …

Member Avatar for Nick Evan
0
93
Member Avatar for javapal

[code] String msg = "place message here"; int cntr = 0; for i = 0 to msg.size; increment i by 1 { if msg.charAt(i) is equal to a white space or == ' ' then increment cntr by 1; } System.out.print(cntr); [/code]

Member Avatar for mrnutty
0
102
Member Avatar for amit.kumar

Read the comments. [CODE] #include<stdio.h> #define max 10 typedef struct { char entry[max]; int top; }stack; int stackfull(stack *s) //SHOULD BE OF TYPE BOOL RETURN { if(s->top==max) // IF FULL return 0; //SHOULD RETURN true else return 1; //ELSE RETURN false } int stackempty(stack *s) //BOOL RETURN TYPE? { // …

Member Avatar for mrnutty
0
110
Member Avatar for Damirz

[QUOTE=soumenpandit;1013101]what is array of pointer[/QUOTE] Well a pointer is an array in some way, so you can think of it as a array of arrays, or a 2d array. [code] //Both Similar char *A[2] = { "hello", "world" }; char B[10][10] = { "hello", "world" }; [/code] They are both …

Member Avatar for mrnutty
0
270
Member Avatar for naej

iostream and cstdlib are called libraries. They contain many methods/functions that will help you from printing to screen to seeding random numbers to sorting arrays, and many more. The #<...> is just the syntax for C++. In java the syntax is import java.SomeLibrary. Each language has is own ways, some …

Member Avatar for mrnutty
0
91
Member Avatar for serkan sendur

In my school : Software Engr : 100% deals with software Computer Science : 70% Software, 30% hardware Computer Engr : 50-50% Software to hardware.

Member Avatar for jingle_br
0
225
Member Avatar for Ilija

[QUOTE=Ilija;1012307]Hello. I`ve been given to make a program for math.After checking it.. it confuses me.I`ve been searching for a solution about my program.I hope u`ll help me with this program.[/QUOTE] So whats the program?

Member Avatar for mrnutty
0
65
Member Avatar for osgiedeprof

which part do you need the help with? Mean = average = Sum of Total elements / Number of elements Median is the middle number in a sorted set of numbers Mode is the most occurring number. To find the Mean you can sum up the total and divide by …

Member Avatar for mrnutty
1
106
Member Avatar for surfer2009

Use vectors if you could, if not then something like this will work : Although its not tested, its the general idea. [code] int base= 10; int * Array = new int[base]; bool end = flase; int i = 0; while(!end) { cout <<" Enter a number : " ; …

Member Avatar for mrnutty
0
106
Member Avatar for scantraXx-

Easy way out, just put a condition to check if "i" is at .size() - 1; if not then print or else not print.

Member Avatar for Poincarre
0
158
Member Avatar for smartness

A few( maybe 2) for loops could solve this problem. Have a for loop, for variable " i" and "a". The equation is pretty forward, unless you don't know what the sigma notation does. What is the "X" variable represents? Is it the user's input ?

Member Avatar for mrnutty
0
140
Member Avatar for adhruv92

Wow, this is funny. Hey, I have a lot of exams right now and I am broke, can you just give me couple of thousands of dollars, so I don't have to work? Just mail it to me.

Member Avatar for triumphost
-3
383
Member Avatar for lexusdominus

"Save" the original content, someway, and compare it later on. There is no other way.

Member Avatar for mrnutty
0
103
Member Avatar for gotnoname

Admin, perhaps it would serve this user best, if you move this thread to game development forum.

Member Avatar for gotnoname
0
161
Member Avatar for ayan2587

The compiler just translate it into binary. You could either, get the input as hex, or decimal or octal. You can't get the input as a number and determine if its decimal or hex. Just get it as hex, and the convert it into decimal if you want or need …

Member Avatar for ayan2587
-1
74
Member Avatar for C++ Beginner

[code] int Num = -1; cin >> Num; //get input while( Num < 0 ) //while input is less than 0 or negative { cout <<" Enter a positive number : "; cin >> Num; } [/code]

Member Avatar for K0ns3rv
-1
3K
Member Avatar for srivastavarupal
Member Avatar for Ponomous

there is a lot of logic errors, but this one is a compile time error : [code] cin << yesorno;[/code] you mean cin >> yesorno , right.

Member Avatar for Ponomous
0
177
Member Avatar for vs49688

Good article, can be found in this [URL="http://www.eternallyconfuzzled.com/tuts/algorithms/jsw_tut_rand.aspx"]Link[/URL]

Member Avatar for mrnutty
0
108
Member Avatar for NinjaLink

How about you explain this code. Tell me what each line does. Then tell me what you think you need to do in order to duplicate a word. [code] void duplicateWords (nodeType*& first, nodeType*& last) { struct nodeType *i; int wordCount = 0; for (i = first; i->link != NULL; …

Member Avatar for NinjaLink
1
217
Member Avatar for ayan2587

Taking a input of hexadecimal number; [code] int s = 0; cin >> hex; //set input to be taken as hexadecimal cin >> s; [/code] Printing hex; [code] int a = 15; cout << hex; //set hex output cout << a; [/code]

Member Avatar for ayan2587
0
331
Member Avatar for DC257209

[QUOTE]If you then want to convert line into an integer, use atoi or strtol. These work on C-style strings, not C++ style strings, so convert line using c_str (); Help with Code Tags C++ Syntax (Toggle Plain Text) getline (cin, line); next = atoi (line.c_str ());[/QUOTE] Disappointed to see you …

Member Avatar for mrnutty
0
145
Member Avatar for maddy1985

[code] std::string str = "abcd123"; int i = 0; while( str[i] && isalpha( str[i] ) ) { cout << str[i] <<" -- is alpha " <<endl; ++i; } [/code]

Member Avatar for mrnutty
-1
100
Member Avatar for ayan2587
Member Avatar for John A
0
161
Member Avatar for that_fox

If this is what you mean. BTW, where is the pointers. And a rule of thumb, when you are using char *, instead of string, you have a bug(In my opinion); [code] //str is the string passed. Key is the key that seperates the word //does not use pointers. void …

Member Avatar for chunalt787
0
168
Member Avatar for rinalini

In my crystal ball, its telling me to [URL="http://www.google.com/search?hl=en&source=hp&q=hamming+code+C%2B%2B&aq=f&oq=&aqi=g1"] Google[/URL] it. Prehaps, that might help.

Member Avatar for mrnutty
0
39
Member Avatar for gauri_phatak_87

Another way using std::string; [code]#include<iostream> #include<algorithm> #include<string> using std::string; using std::cout; int toChar(char c){ return c + '0'; } string convertBase10_To(int changeToRadix, int base10Number, int paddingEveryUnits = 4) { string Str = ""; //Did not want to support radix greater than 10. You do it. if(!changeToRadix || changeToRadix > 10) …

Member Avatar for mrnutty
0
752
Member Avatar for Ashishinani1756
Member Avatar for mrnutty
0
93
Member Avatar for MMD88

create function; [code] void getFact(long N); //assume already created for(int i = 0; i < MAX; i++) Array[i] = getFact(i); [/code]

Member Avatar for quuba
0
121
Member Avatar for hao001

Maybe this will help : [code] #include<iostream> using namespace std; int main() { for(int i=5;i>=1;i--) { for(int j=5-i;j>=1;j--) { cout<<"-"; } for(int k=1;k<=i;k++) { cout<<"* "; } cout<<endl; } return 0; } [/code] Look at the output, and trace the loop from i = 5 till i = 1.

Member Avatar for hao001
0
91
Member Avatar for geg13

I won't even say anything. Just, Here : [code] #include <iostream> #include <iomanip> using namespace std; int main() { cout << "This is a template.\n"; cin.get(); return 0; } [/code]

Member Avatar for geg13
0
91
Member Avatar for stuartc

Get started. [code] int main() { //Create array //use a for loop to ask user for input // for i from 0 to array size cin >> myArray[i]; //create a sum,average, high and low variable; //Find sum first, initialize it to 0 first; //use a for loop from i = …

Member Avatar for geoffy0404
-3
100
Member Avatar for uzimuzi

[QUOTE=uzimuzi;1001625][COLOR="Green"]Thank you; ^ and ^^ for your prompt reply :) [/COLOR] I have [B]another problem[/B] similar problem; i.e. [U]now ONCE i have declared[/U] a [B]char[/B] array of a particular size; if I add more values into other indexes of it; it stores them; its like the [B]char[/B] array is [I]EXPANDING …

Member Avatar for uzimuzi
-1
331
Member Avatar for Peppercat101

Try this. And inline won't do anything helpful by the way. [CODE] ostream& operator << (ostream& os, FixedSizeMatrix& obj) { obj.print(os); return os; }[/CODE]

Member Avatar for mrnutty
0
128
Member Avatar for alvalany
Member Avatar for KimJack

Yes. In fact thats very common, using 1d array as a mimic of a 2d. [code] final int ROW = 5; final int COL = 5 char[] Letters = new char[ ROW * COL]; for(int i = 0; i < ROW * COL; i++) Letters[i] = (char)( 'A' + i …

Member Avatar for anupam_smart
0
161
Member Avatar for gibson.nathan

It would help if you created a few function that returns either lowercase, uppercase , number or a punctuations. The in your randomLowercase(int len) function you can something like for(int i = 0; i< len; i++ ) randomString += getRandLowerCaseCharacter(); //getRandLowerCaseCharacter returns a char from 'a' to 'z'; Similarly, you …

Member Avatar for VernonDozier
2
1K
Member Avatar for hamzak

Its amazing what google can do. Here is one I found, [URL="http://code.msdn.microsoft.com/RubiksCubeSolver/Release/ProjectReleases.aspx?ReleaseId=712"]Link[/URL]

Member Avatar for mrnutty
0
56
Member Avatar for BeyondTheEye

The proper use of delete and delete [] [code] int *Num = new int; int *Array = new int[5]; delete Num; //good delete [] Num; //Bad -- undefined delete [] Array; //good delete Array; //bad --undefined [/code] As you can see, you have : [code] Category* pCat = new Category; …

Member Avatar for mrnutty
0
98

The End.