2,712 Posted Topics

Member Avatar for Soileau

Also, notice that your case function looks like this : [code] switch(number) { case 1: //blah case 2: //blah } [/code] There is a problem with that. The problem is that you used constant numbers in your switch case. Usually, those numbers means something, so making a const variable for …

Member Avatar for WaltP
0
182
Member Avatar for gamerchick

[QUOTE=hag++;1108338]You do need a second for loop (one for the rows, one for the columns, in the array) It may be easier to use pointers: [CODE] int* return_ptr(int str[][20], int x, int max_rows, int max_col) { int* a_ptr = new int; for (int i = 0; i < max_rows; i++) …

Member Avatar for dusktreader
0
230
Member Avatar for nainish

[QUOTE=hag++;1108268]Hey, welcome to the forums. Typically this forum is used for learning/ correcting purposes even on the more advanced stuff (which is in the 'Please read before posting' section of the forum rules) which means that forum members are not typically going to do the work for you. Instead, post …

Member Avatar for hag++
-2
142
Member Avatar for jeffjnsb

Here is an example : 5. Write a C++ statement that defines a Square object named square1 with side length 5. [code] Square square1 = Square(5); [/code] The above is assuming the class is Square is similar to this : [code] class Square{ private: int len_; public: Square(const int Length) …

Member Avatar for mrnutty
0
180
Member Avatar for anthony5557
Member Avatar for anthony5557

if you mean for example , <input> hello <output> olleh then all you have to do is this : [code] string input; cin >> input; reverse(input.begin(),input.end()); cout << input << endl; [/code]

Member Avatar for hag++
0
2K
Member Avatar for pradeey
Member Avatar for Rajesh R Subram
0
139
Member Avatar for clutchkiller

>>When assigning a pointer variable, it must always point to an address. Thats incorrect. Hint what about null pointers?

Member Avatar for clutchkiller
0
77
Member Avatar for jigglywiggly

It could look something like this, simplified for your pleasure( not Compiled) [code] typedef int DataType; class SingleList { public: struct Node{ DataType value; Node * nextNode; Node(const DataType& initVal) : value(initVal), nextNode(0){} }; typedef Node* NodePtr; private: NodePtr front_; NodePtr back_; public: SingleList() : front_(0), back_(0) {} SingleList(const size_t …

Member Avatar for mrnutty
0
323
Member Avatar for fadia
Member Avatar for tmayb

I just did this last semester for my java class. If that makes you feel better.

Member Avatar for mrnutty
-2
100
Member Avatar for xxmp

You need a forward decleration. Put this at the top of your file : [code] template <class typos_stoixeiou> struct akmi; template <class typos_stoixeiou> struct korifi{ ... } [/code]

Member Avatar for tkud
0
103
Member Avatar for flyingguitar

when you use cin >> , it reads until it sees a space. Do this : [code] char firstName[100] = {0}; char lastName[100] = {0}; cin >> firstName >> lastName; [/code] Thats the easy solution and error prone. The better solution is the use strings. [code] string firstName, lastName; cin …

Member Avatar for flyingguitar
1
96
Member Avatar for chukka32

Use this : [code] #include <iostream> #include <string> using namespace std; int getInt(const string& messageBeforeInput){ cout << messageBeforeInput; int result = 0; while(! (cin >> result) ){ //check for bad input cout << messageBeforeInput ; cin.clear(); //clear the stream bits while(cin.get() != '\n') continue; //get rid of the junk } …

Member Avatar for chukka32
0
269
Member Avatar for Phil++

>>I thought about using an Exception There is no need to use exception here because it will only complicate your code. Why not just display nothing? Or display a message saying no employees to show. Do something like this : [code] if(choice == VIEW_EMPLOYEES){ if(employees.empty()) { displayErrorMessage() } else displayEmployees(); …

Member Avatar for mrnutty
0
74
Member Avatar for nichya88

>> The program cannot get the name. In fact, it doesn't allow me to type That because when you read the age, the stream reads the number and the newline character. That new line character is being read into the variable name. To fix that problem add this : [code] …

Member Avatar for nichya88
0
145
Member Avatar for phil750

1) Do you know how to access the elements in the array 2) Do you know how to use a for loop 3) Do you know how to use add a value If so then you know how to do it, else ask about a even more specific question.

Member Avatar for mrnutty
0
97
Member Avatar for sidra 100

>>void expense::setmonth() { cout<<"\n Enter the Month: "; getMonth(); } Change to : [code] void expense::setmonth(std::string month){ currentMonth= month; } [/code] I am not sure what your class does exactly but general idea is given above.

Member Avatar for jonsca
0
340
Member Avatar for Drenon

printf is faster than cout, in visual studio 2008 express. Try substituting that. How about you post some code that you might think is the bottle neck of your program and we will see how you can improve it.

Member Avatar for Drenon
0
210
Member Avatar for alexa868

Sin(x) = x - x^3/3! + x^5/5! + x^7/7! ... Cos(x) = 1 - x^2/2! + x^4/4! - x^6/6! ... Cos(x) = Sin( x - 90 ) ; //assuming x is in degrees Tan(x) = Sin(X)/cos(X) "!" means factorial. for example to calculate Sinus you can do this : [code] …

Member Avatar for mrnutty
0
360
Member Avatar for cwarn23

>> a+b=23 Not taking into account floating points and just positive natural numbers. Then if b > 23 then no Answer Possible if b = 23, then a = 0; if b = 22, then a = 1 if b = 22, then a = 2 General Equation : B …

Member Avatar for mrnutty
0
137
Member Avatar for Annettest

>>[B]u = new double[I*sizeof(double)];[/B] No! This is not C. In C++ its used like this : [B] u = new double[ I ]; [/B] The value inside [ ], is the number of elements. No need for the sizeof. Put your printing loop out side separately. Like this : [code] …

Member Avatar for Annettest
0
178
Member Avatar for awaisysf
Member Avatar for Stefano Mtangoo
Member Avatar for hbweb500

>> But I feel that this is abusing memory quite a bit how so ? >> My feeling is that it might not be necessary, or even possible, to use the new operator with vectors. It is possible to use the new operator for vectors. It is not necessary to …

Member Avatar for mrnutty
0
216
Member Avatar for Salem

I think either one of these will do for me : [I]That idea was [B]sooo [/B]not [B]stupiiiddd[/B][/I] [I]That idea was so not stupid<sarcasm>[/I] [I]That idea was so not stupid, cough* bullSh**cough[/I]

Member Avatar for jonsca
3
139
Member Avatar for rwill357

You are on the right track. Consider making the name of that function better. Also you might want to make the base case more explicit like this : [code] void convertDecimalToRadix(int num, int base) { if( num == 0 ) return; //base case binequ(num/base, base); cout<< num % base; } …

Member Avatar for program_helm
0
128
Member Avatar for shaunmccann1

Just use the stringstream to break a string into tokens : [code] stringstream tokenBreaker; string aLine = "Please break this into six tokens"; tokenBreaker << aLine; //insert string string tokens[7]; //for now lets not use vectors and do it manually int currentToken = 0; while( tokenBreaker >> tokens[currentToken] && currentToken …

Member Avatar for shaunmccann1
0
162
Member Avatar for froggy1976

[QUOTE=jonsca;1103782]Also, your method definitions, e.g., [code] void dayOfTheWeek::printDay() { cout << "Today is: " << day[dayNum] << endl << endl; }[COLOR="Red"];[/COLOR] [/code] and onward should not end with a semicolon after the brace (you do still need the ones at the end of your class declaration and your const array).[/QUOTE] …

Member Avatar for mitrmkar
0
129
Member Avatar for Phil++

Use vectors of string. [code] vector< string > customers; //size == 0 //do stuff //menu stuff; if(!customers.empty() ) cout << "Display Members ? \n"; //other menu stuff [/code] To add customers, you can use the push_back method of vectors; [code] vector< string > customers; customers.push_back("Phil"); customers.push_back("Tyler"); [/code] Here is some …

Member Avatar for abdelhakeem
0
106
Member Avatar for PhiberOptik
Member Avatar for wellibedamned

1) How about using vectors ? 2) How about using 1d array to represent 2d ? 3) In passing 2D arrays, you need to specify the number of columns before hand, like so : [code] const int COL = 5; void init(int Array[][COL], const int ROW){ //TODO logic here } …

Member Avatar for mrnutty
0
160
Member Avatar for grealish234

This function can be more simple : [code] int isnum(const char *p) { if (*p) { char c; while ((c=*p++)) { if (!isdigit(c)) return 0; } return 1; } return 0; } [/code] Maybe to this ? [code] bool isDigits(const char * strNum){ while(*strNum){ if(isdigit(*strNum++) ) continue; else return false; …

Member Avatar for mrnutty
2
114
Member Avatar for rohitn

operator new returns a void*, in which it is converted implicitly to whatever type you are using with assignment operator. operator delete does not return anything.

Member Avatar for Nikhar
0
100
Member Avatar for Ancient Dragon

>>[b] Who would design a page with a bright red background and white text[/b] Obviously reptilians! Their visions can handle colors better than we can.

Member Avatar for WaltP
1
325
Member Avatar for athlon32

Obviously your add function is wrong. How about you ditch the sorting part of this and make a regular linked list, unless you haven't done that already? And your print function is wrong : [code] void printall() { for(node* x = bottom; [COLOR="Red"]x [/COLOR]!= NULL;) { std::cout <<x->data<<"\n"; x = …

Member Avatar for Ancient Dragon
0
90
Member Avatar for drjay1627

Google blender. Its a good 3d modeler. You can create some 3d model and use C++ to load it in, and display it with some API like openGL or direct3D.

Member Avatar for BountyX
0
81
Member Avatar for sonisuhas

>>[b] Computers can't generate random numbers the way our mind does[/b] Citation please? I am interested on where you got this info.

Member Avatar for Narue
0
137
Member Avatar for avirag

A char cannot hold "312,000". You are probably thinking about an array of chars, or a string. Use something like this : [code] #include <iostream> #include <string> #include <sstream> using namespace std; string deleteChar(string str, char charDelete = ','){ size_t pos = str.find(charDelete); if(pos == string::npos) return str; str.erase( pos, …

Member Avatar for Narue
0
2K
Member Avatar for D137Pi
Member Avatar for thariqrasheed

Basically it shifts bits. Take for example, the number 4. In binary, its 0100. Each digit in the binary for is called bits. 8 bits = 1 byte. If we use the bitshift operator like this [code] int shiftVal = 1; int value = (4 << shiftVal); [/code] we shift …

Member Avatar for mrnutty
0
112
Member Avatar for mrnutty

You know you are a geek you find it more natural to count numbers in the power of 2 then decimal.

Member Avatar for mrnutty
1
329
Member Avatar for mrnutty

Some background. We all used the string class, but some of you might not know that string is just a typedef of basic_string. In fact here is the typedef you might find when looking in the XString library. [code] typedef basic_string<char, char_traits<char>, allocator<char> > string; [/code] This code snippet shows …

Member Avatar for Dave Sinkula
2
3K
Member Avatar for KonkaNok
Member Avatar for ball3r

For your print maze do this instead, [code] void printMaze(char maze[100][100],int mazeSize) { for(int i = 0; i < mazeSize; i++)//printing the maze { for(int j = 0; j < mazeSize;j++) cout << maze[i][j] << " "; cout << endl; } } [/code] As for your problem, where does the …

Member Avatar for WaltP
0
5K
Member Avatar for kavourdoukos

>>[b] You need to simulate an array with a pointer and dynamic memory[/b] Better yet, you should use the standard containers. Depending on your situation, certain one will be better suited. But Below I will give an example of how to use std::vector to simulate a variable sized array. [code] …

Member Avatar for mrnutty
0
123
Member Avatar for zukkoor

For every C++ program, you need a starting point, and that starting point should be either "int main()" or "int main(char *arg, char *argv[])" Here is a complete C++ program : [code] #include <iostream> using namespace std; int zero(){ return 0; } int main() { int x = zero(); cout …

Member Avatar for jonsca
0
3K
Member Avatar for san_fran_crisko

Just go for C++. Learning C afterwards will be easy. And you will see the real difference between the two.

Member Avatar for Narue
0
286
Member Avatar for mrnutty

My friend passed it onto me and its only right I pass it onto [URL="http://www.maniacworld.com/maze_game.htm"] you [/URL]. Its the most simple game. Can you pass all 4 levels?

Member Avatar for Will Gresham
0
62
Member Avatar for MCMLXXXVIII

The End.