2,712 Posted Topics

Member Avatar for chandagondhali
Member Avatar for marlinssmith

before the loop ask the user to enter a number and set min/max to that number, then go onto the while loop.

Member Avatar for mrnutty
0
115
Member Avatar for jakesee

having const after a member function means that, that function will not and shall not change any of its variables.

Member Avatar for jakesee
-1
95
Member Avatar for johndoe123
Member Avatar for Nick Evan
0
10K
Member Avatar for Vallnerik
Member Avatar for I_Empire

Did you try it? [code] #include <iostream> using namespace std; class A { public: A() { } template<typename T> void Print(T a) { cout<<a<<endl; } }; int main() { A t; t.Print(3.1415f); //implicitly t.Print<unsigned int>(100); //explicitly return 0; } [/code]

Member Avatar for siddhant3s
0
277
Member Avatar for NathanOliver

Yes, use template. You could use template specialization, to make sure that the template parameters is a number. Here is a way to do that : [code] #include <iostream> using namespace std; template<typename Type> struct is_numeric { static const int i = 0; }; //Template specilization template<> struct is_numeric<short> { …

Member Avatar for NathanOliver
0
144
Member Avatar for acidnynex
Member Avatar for Trekk
Member Avatar for BestJewSinceJC
1
118
Member Avatar for ROTC89

Search the forum first. See if that helps. Then ask question if it comes empty.

Member Avatar for sandeepss6s
0
127
Member Avatar for vileoxidation
Member Avatar for feartrich

use for loop. It will be conceptually easier. [code] int F =5; int R = 1; for i = F to i >1 ; i-- { R equals R times F; F equals F minus 1; } [/code]

Member Avatar for nomemory
0
99
Member Avatar for shahanakazi

Here is your code indented with code tags. One problem with your function is that you never declared s1 and s2. Below code fixes that : [code] #include <iostream> using namespace std; void drawShape(int nrP) { int s1 = 0,s2 = 0; //(NEW) for (int i = 1; i <= …

Member Avatar for Barefootsanders
0
160
Member Avatar for axelle.eichner

[code] //Create a string and initialize it to some string literal for i = 0 to i less than the string.size ; i++) //use string.charAt(i) to print + "\n"; [/code]

Member Avatar for javed123
0
148
Member Avatar for Anjana Patel

[URL="http://en.wikipedia.org/wiki/Gauss%E2%80%93Seidel_method"]Link[/URL]

Member Avatar for ithelp
-1
129
Member Avatar for DemonixXV2
Member Avatar for lotrsimp12345

Your copy constructor is not complete. [code] my_int_vector::my_int_vector(const my_int_vector& b) { numbers=new int[capacit]; for(size_t j=0; j<siz; j++) { numbers[j]=b.numbers[j]; } } [/code] What happens is numbers is already pointing at another memory location. What happens if the copy constructor is copying its self?

Member Avatar for mrnutty
0
253
Member Avatar for Doughnuts

simplify. 1) Make a bool function that takes a int i as a parameter and checks if it is a prime or not. 2) inside your loop, check if i to MAX is a prime. your function prototype might look like this : bool isPrime(int num); HINTS : a) How …

Member Avatar for Doughnuts
0
284
Member Avatar for uNpReDiCtAbLe

1) No Code tags 2) [code] int opt,x,y,fact,ans; // right now all variable has junk value for(ans=opt;ans!=0;ans++) //Read as ans = junkvalue, while junk is != 0, junk++ [/code] 3) Didn't bother with the rest

Member Avatar for sfuo
0
136
Member Avatar for Flapjack

[QUOTE=Flapjack;991144]I cant take const out. The teacher wants us to us his function and develop our code around it.[/QUOTE] Well there is [URL="http://www.cppreference.com/wiki/keywords/const_cast"]const_cast[/URL] but generally, you shouldn't have to do this.

Member Avatar for Flapjack
0
840
Member Avatar for adsiq

usually : [code] std::ostream& operator <<(std::ostream& ostrm) { ostrm << "Hello its overloaded\n"; return ostrm; } std::istream& operator >>(std::istream& istrm) { cout<<"Enter a number : "; istrm >> MyClass::myNumber; return istrm; } [/code] note overloading the << operator should be a friend, so you can use it like this : …

Member Avatar for shaneselling
1
121
Member Avatar for Awebb999

1) you could create a vector. 2) Initialize it with the array content 3) use std::sort on the vector 4) use std::unique on vector 5) Then print out the vector

Member Avatar for Sky Diploma
0
72
Member Avatar for tomtetlaw

[CODE] - error C2143: syntax error : missing ';' before '.' - missing type specifier - int assumed. Note: C++ does not support default-int - 'test_player' : redefinition; different basic types [/CODE]

Member Avatar for Sky Diploma
0
113
Member Avatar for AirGear

your haven't initialized the variable "a". And it has to be const, when using it to determine the size of an array. [code] const int A = 10; string str[A]; //good int b = 3; string str[b]; //error[/code]

Member Avatar for AirGear
0
249
Member Avatar for aomran
Member Avatar for mrnutty
0
168
Member Avatar for sfuo

There is also [URL="http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=/com.ibm.xlcpp8l.doc/language/ref/cplr385.htm"]conversion Function[/URL] : [code] #include<iostream> #include<cstring> using namespace std; class Letters { private: char str[50]; public: Letters() { str[0] = '\0';} Letters(const char * p) { strcpy(str,p); } operator const char *() { return str; } //conversion function }; int main() { Letters str("hello world"); cout<<str; } …

Member Avatar for mrnutty
0
252
Member Avatar for kele1

First seed your rand function. [code] srand(time(0)); [/code] The this code : [code] for (int toss = 0; toss < coinToss; toss++) { flip(); if (toss == 1) heads++; else tails++; } [/code] is wrong. You need to assign the value return to a variable and then use it to …

Member Avatar for NathanOliver
0
234
Member Avatar for MrNoob

[QUOTE=gerard4143;990400]The unnamed fields may just be padding so that the structure's data is laid out correctly...Gerard4143[/QUOTE] Yes, structure goes by units of 4.

Member Avatar for codeguru_2009
0
145
Member Avatar for Der_sed

first this is wrong : [code] for (int i=0; i<=arrSize; i++) //it should be i < arrSize myArr[i]=rand(); //creating array with random numbers [/code] The same goes for sorting and displaying numbers.

Member Avatar for vmanes
0
114
Member Avatar for cookies

1) Dont use system's command 2) To answer your question something like this : ? [code] string command = "color "; string input = ""; cin >> input; command += input; system(command.c_str()); [/code]

Member Avatar for cookies
0
77
Member Avatar for KonkaNok

portability : "The actual type of size_t is platform-dependent; a common mistake is to assume size_t is the same as unsigned int, which can lead to programming errors, particularly as 64-bit architectures become more prevalent"

Member Avatar for KonkaNok
0
148
Member Avatar for mostermand

[QUOTE=mostermand;990915]Too time consuming. I would rather not do it at all then And about the code snippet, if I create an instance of Mother, and call HandleMessage<10> it would print "It works!\n". But if I call it with any other value it would do nothing, the reason I am not …

Member Avatar for mostermand
0
175
Member Avatar for kyumi419

Have a left, middle, and end variable. Make middle static. Move left up 1, move end down 1. If left == mid || right == mid then stop.

Member Avatar for kyumi419
0
205
Member Avatar for MattyRobot

opengl is a graphics library while glut is not. You use glut with opengl to handle graphics. glut handles with mostly the input. It could create the graphics window, handle key input and some other fancy stuff. You use opengl to draw primitives onto the window that glut creates.

Member Avatar for mrnutty
0
134
Member Avatar for sftwr21

[code] int cnt = 0; for infinite loop { //do stuff if(//do stuff is what i need) // then break; else cnt++; //if cnt is above the limit then break; }[/code]

Member Avatar for sftwr21
0
214
Member Avatar for chunalt787

Use the error handling that already built in, called [URL="http://www.cplusplus.com/reference/std/stdexcept/"]stdexcept[/URL]

Member Avatar for David Boon
0
214
Member Avatar for yonghc

To convert string to numeric datatype look [URL="http://www.daniweb.com/code/snippet217456.html"]here[/URL]

Member Avatar for yonghc
0
414
Member Avatar for javanub123
Member Avatar for icu222much

[quote] can't I just use a string?[/quote] Yes you can : [code] #include <iostream> #include <string> using namespace std; struct Student { string firstName; string lastName; bool canadianship; int grades[10]; }; Student newStudent[10]; void addFirstName() { string name; cout << "Student Name: "; cin >> name; newStudent[0].firstName = name; } …

Member Avatar for icu222much
0
74
Member Avatar for CD-4+
Member Avatar for sjcomp

[QUOTE=sjcomp;990316]Thanks William, thanks for the suggestion. I understand how it can be done. But before I jump in and start implementing it myself I would like to make sure that I can not use the code that already exists. It seems reasonable to expect that such a code exists, though.[/QUOTE] …

Member Avatar for mrnutty
0
111
Member Avatar for daviddoria
Member Avatar for Trekker182

[QUOTE=Trekker182;988208]I think I just need to tell the sort function sort by ascending order except when you encounter "a" "e" "i" "o" or "u" but am not sure how. Would it have something to do with the p parameter?[/QUOTE] Well if you want to do that, then use a compare …

Member Avatar for Trekker182
0
198
Member Avatar for johndoe444
Member Avatar for johndoe444
0
142
Member Avatar for Supercharger

//check out the code snippet, [URL="http://www.daniweb.com/code/snippet217455.html"]here[/URL] int random(int low, int high) { return } [code] //use logic to find the min element //assign initial min element to A[0]; //search through loop seeing if other element's value are //greater than min element value if so the reassign min element //other wise …

Member Avatar for dgr231
0
156
Member Avatar for Warcat

Make a function that return a random int from 1-6; then player1 = randomDiceRoll(); player2 = randomeDiceRoll(); //and so on. have a counter that counts points. int playerPoints =0; int compPoints = 0; //use a while loop while(true) { //roll dice //check winner //add points to winner //check if game …

Member Avatar for sfuo
0
113
Member Avatar for GooeyG

[quote] The errors that I have are: [/quote] [quote] error C2228: left of '.print' must have class/struct/union [/quote] This is from this code : [code] //prompt customer for savings balance and print the balance out savingsAccount.calculateMonthylyInterest().print(); [/code] To solve it you can do 2 things : 1) Make calculate return …

Member Avatar for GooeyG
0
149
Member Avatar for gretty

Its because of logic : [code] for (int i=0; i<list.size(); i++) { ...} [/code] Lets make a table : [code] i list.size() list.top i < list.size() ---------------------------------------------- 0 3 2323 true 1 2 10 true 1 1 20 false [/code] So what a for loop does is this :[code] for( …

Member Avatar for mrnutty
0
125
Member Avatar for heroic

google opengl loading texture tutorial. You will find how to load in image files.

Member Avatar for Talguy
0
147
Member Avatar for Cheesy74

The End.