2,712 Posted Topics
Re: 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 … | |
Re: 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 - … | |
Re: [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 | |
Re: [URL="http://www.cplusplus.com/reference/iostream/stringstream/stringstream/"]http://www.cplusplus.com/reference/iostream/stringstream/stringstream/[/URL] | |
Re: How about you just ask your teacher since it will be easier and more straight forward. | |
Re: [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. | |
Re: [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 | |
Re: 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. | |
Re: 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 … | |
Re: 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] | |
Re: [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 ) { … | |
Re: [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] | |
Re: 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? { // … | |
Re: [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 … | |
Re: 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 … | |
Re: In my school : Software Engr : 100% deals with software Computer Science : 70% Software, 30% hardware Computer Engr : 50-50% Software to hardware. | |
Re: [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? | |
Re: 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 … | |
Re: 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 : " ; … | |
Re: Easy way out, just put a condition to check if "i" is at .size() - 1; if not then print or else not print. | |
Re: 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 ? | |
Re: 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. | |
Re: "Save" the original content, someway, and compare it later on. There is no other way. | |
Re: Admin, perhaps it would serve this user best, if you move this thread to game development forum. | |
Re: 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 … | |
Re: [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] | |
| |
Re: there is a lot of logic errors, but this one is a compile time error : [code] cin << yesorno;[/code] you mean cin >> yesorno , right. | |
![]() | Re: Good article, can be found in this [URL="http://www.eternallyconfuzzled.com/tuts/algorithms/jsw_tut_rand.aspx"]Link[/URL] |
Re: 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; … | |
Re: 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] | |
Re: [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 … | |
Re: [code] std::string str = "abcd123"; int i = 0; while( str[i] && isalpha( str[i] ) ) { cout << str[i] <<" -- is alpha " <<endl; ++i; } [/code] | |
Re: Look at your other post. And don't double post. Be patience. | |
Re: 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 … | |
Re: 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. | |
Re: 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) … | |
Re: Another [URL="http://reconnetworks.net/forum/index.php/topic,1750.0.html"]Link[/URL] | |
Re: create function; [code] void getFact(long N); //assume already created for(int i = 0; i < MAX; i++) Array[i] = getFact(i); [/code] | |
Re: 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. | |
Re: 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] | |
Re: 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 = … | |
Re: [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 … | |
Re: 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] | |
Re: 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 … | |
Re: 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 … | |
Re: 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] | |
Re: 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; … |
The End.