- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 4
- Posts with Upvotes
- 4
- Upvoting Members
- 4
- Downvotes Received
- 3
- Posts with Downvotes
- 3
- Downvoting Members
- 3
38 Posted Topics
Hi guys, I'm quite new to C++, I have just recently gone through 3/4 of SAMS teach yourself C++ in 21 days and I am hoping to start programming my first object-oriented game. I have created a few games in the past (you can check them out on my site … | |
Re: Here's a working example i just wrote. I've also used the enum type you guys were talking about, plus i added another of my own. Study this well and u'll c what i was going for. Hope it helps, byee [code] #include <iostream> #include <ctime> using namespace std; enum Choice … | |
Re: Here's something that you might find useful. Because the description of the problem isnt really the clearest it could be, I made this little program up to help you understand what should happen. Its using a functino called DoMenu which displays the menu and gets input from there. [code] #include … | |
![]() | Re: yep thats fine.. also make sure you return 0 when you declare int main(), otherwise declare void main() The final program should look like this: (I changed the name of the function perfect(...) to perfect_function(...) and i added a return 0 at the end of main) [code] #include <iostream> using … |
Re: Here;s something you can work on. It may not be exactly what you need but its a basis at least. Also, why do you need to check if the second number of the division is zero, from the second you say it will accept values from 1-20?? Anyway, I put … | |
Hi, can anyone tell me how to configure DirectX (December 2006) in MS visual C++ 6.0 please, or at least where or what to read to finally do it? I’m having a real hard time figuring this out thanks | |
Re: First of all, here is your code indented with some comments: [code] #include <stdio> //void triangle(int n); // function prototype does not match the declaration. should be: void render_triangle(int height); // or: void render_triangle(int n); int main() { int rowLength = 0; int rowHeight = 0; printf("\n Enter a number … | |
Re: I've read SAMS teach yourself C++ in 21 days and Herbert Schildt's C++ from the ground up. I honestly recommend the first one though as it's code is much clearer and easier to understand. The second book though goes more into the containers such as lists and vectors and as … | |
Re: You can just do this. It checks through all the elements in the array and finds out each check which is the smallest, biggest and average value of the array so far. At the end you have your results [code] #include <iostream> using namespace std; const int MAX = 10; … | |
[I]<< This thread is split off from a discussion that originated here: [thread]62976[/thread] >>[/I] Here;s something you can work on. It may not be exactly what you need but its a basis at least. Also, why do you need to check if the second number of the division is zero, … | |
Re: You've got to understand you only need to be dealing with one instance of class Tollbooth. You declare 3 in your main! a,b,and toll. Just a hint, you dont need any parameters in your accessor functions! You can simply manipulate the variables cartotal and cash without any nums or num1s.. … | |
Re: It works fine on my compiler :-S Try declaring a boolean variable and have that in the while loop [code] bool keepLooping = true; ... while (keepLooping) { ... } [/code] Or simply use the forever loop [code] for (;;) { ... } [/code] | |
Re: I've commented out your mistakes and placed the correct bits where necessary. I also commented what you had wrong. Its mostly syntax errors, nothing too bad, just keep a eye out for these things. Also, always make sure your main() returns a 0. You had this code, but right down … ![]() | |
Re: Yep, u need to use the index in your loop to make any sense of using it.. something like [code] for (index=0; index<NUM_PLAYERS; index++) { cout << "Name: " << players[index].name << endl; cout << "Number: " << players[index].playNum << endl; cout << "Score: " << players[index].Points << endl; } … | |
Re: Here's a working solution. Ok what I did is: 1. Changed the sort algorithm from bubble to selection sort, passing the array in by reference. 2. Changed both sortArray and ShowArray functions to void, the needn't be double, they dont return anything. 3. Changed the count variable from 0 to … | |
Re: [code] #include <iostream> using namespace std; void function(char *name); int main() { char string[20]; char *aString=string; function (aString); return 0; } void function(char *name) { cout<< "enter name: "; //cin >> name; cin.get(name,19); // so you can get more than one word in your string cout << name; } [/code] | |
Re: Of my studying and understanding, Virtual Functions are used only for polymorphism. Use virtual functions ONLY if you know those functions wil be overloaded or overrided in derived classes. Don't make a habit of using virtual in any function because "you may need to overload it later on". Now, for … | |
Re: An easier way of doing this is something like: [code] #include<iostream> #include<string> using namespace std; int main() { string myString = "momimom"; bool check = true; int i=0; int size = myString.size(); for (i=0; i<(size/2)+1; i++) { if (myString[i] != myString[size-i-1]) check = false; } if (check) cout << "This … | |
Re: This is one way of handling it. Study it and you'll get your head around it. Hope it helps byeee [code] #include<iostream> using namespace std; int main() { int input; int i; int value; int sum=0; // must be initialized with 0 cout << "How many numbers to enter?: "; … | |
Re: Here's a working solution. Study it hard and youl'l figure it out. Hope it helps byeee [code] //This progam accepts marks of 4 different subjects by 5 students. //Then calculates the average score of each subject and displays the //result. #include<iostream> using namespace std; int main() { int value=0, i=0, … | |
Re: your code is fine man.. I enter 5 numbers (one for each type) and the output seems correct to me. Dont know what went wrong on your side?!?... | |
Re: int main() is used to return 0 at the end. This 0 is returned to the Operating system to denote that the function main() - which is the only function called by the operating system and that's why its so special - has completed successfully. Always use int main() and … | |
Re: I guess this problem is fixed. The final code should look something like: [code] #include <iostream> #include <iomanip> #include <string> using namespace std; // prototypes float division_input(string); void highest_division(float, float, float, float); int main() { cout << "This program written for cs102 Online." << endl; float nE=0,sE=0,nW=0,sW=0; nE = division_input("North … | |
Re: you can use system("cls") but that will clear the entire screen, not just a part of it. Beware that this is an OS command though | |
Re: long integers also have a maximum value. They are made up of 4 bytes (32bits) (depending on each pc) and can only hold upto a certain number. If you try to go past this number you will wrap around and start at the beginning. Try using unsigned long int, which … | |
Re: Here's how its supposed to handle. Check it out and hope it helps [code] #include <iostream> using namespace std; int main() { int num1=0; int num2=0; int quotient=0; int remainder=0; cout << "first number entered: "; cin >> num1; cout << "second number entered: "; cin >> num2; if (num2==0) … | |
Re: This is how to implement your function. Check it out, hope it helps [code] int indexOfMin(const string a[], int n) // i'm assuming n is the number of { // elements in the array?? int min=0; // minimum of all strings if (n<0) // check if empty first { return … | |
Re: I am guilty of this, I'll be honest. I know it is important to indent and indent properly, it is industry standard, and it is simply utilitarian. Well [URL="http://www.daniweb.com/techtalkforums/member121974.html"]sharky_machine[/URL] you're correct upto a point. Industry standard however depends on the industry and company you work for. "Good" indencing is not … | |
Re: [code] int SomeArray[5][2] = { {0,0}, {1,2}, {2,4}, {3,6}, {4,8}} [/code] This creates a 2-dimensional array. All together this array has 10 elements. Which is the first index of this array? SomeArray[0][0]. The initialization states that this is equal to 0 (the first 0 in the {0,0}). Which is the … | |
Re: Here's the code. You dont really need the last two #includes in the program.. Not sure if you needed them for later though.. [code] #include<iostream> #include<iomanip> using namespace std; int main () { const int NUMROWS = 5; const int NUMCOLS = 3; int i, j, num = 0; int … | |
Re: if you're using C++: 1st thing to do: [code]#include <fstream>[/code] 2nd thing open the file for output obviously if you're going to append and change the default behaviour of ofstream: [code]ofstream fout(<filename>, ios::app)[/code] Then go on with your program. Dont forget to close your file at the end!! | |
Re: getline() throws away the \n null character at the end of a string and therefore makes a mess when trying to fluch the buffer. Using cin.get() makes everything much more comfortable | |
Re: OK what i did first of all is clear up your code.. Please start using spaces, ur killing us here! I simply sent in the check boolean variable into the IsValid function by reference. This clears up your whole program [code] #include <iostream> #include <string> using namespace std; void GetScore(double … | |
Re: Yeah, integers wrap around themselves. For example if you had a signed (takes positive and negative numbers, i think the min is -32,000 something and max is 32,000 something), then when you get to that maximum number and add 1 it will wrap around and start from its min. If … | |
Re: Here's a working example of how to reverse a string using a function. Hope this helps, good luck! [code] #include <iostream> using namespace std; void ReverseString(char string1[], char reversed[]); int main() { const int MAX = 80; char string1[MAX]; char reversed[MAX]; cout << "Enter your string: "; cin.get(string1,MAX); ReverseString(string1, reversed); … | |
Re: Here's the whole program in one file. If you want you can divide this code and include the files as needed. I've also included a menu loop so you dont have to keep on running the program again and again. Good luck! [code] #include using namespace std; class Counter { … | |
Re: Here's the code for a working solution i just made. What you do with the counters at the end is up to you though. Good luck! [code] #include <iostream> using namespace std; int main() { // counter is an int array containing a counter for each possible character // entered. … | |
Re: Here's the code for the first problem: [code] #include <iostream> using namespace std; int main() { int num; do { cout << "Enter a number > 0: "; cin >> num; } while (num <= 0); for (int j=num; j>0; j--) { for (int i=1; i<=j; i++) cout << i … |