I am in the process of creating a game that has two players machine and person. The player is selected randomly each round. So if the player is selected, he needs to choose a number from 1-9. Then the machine needs to choose another new number either in the same row or colunm.(i figured out how to check against col.and row). Then keep going until someone reaches 31.
I'm stuck on how to add the numbers from previous rounds and have them reflect in the new rounds. While at the same time using the last entered number(last numbers) as a reference has to whether or not the new number is valid.
Ok I created a while loop as suggested. But it is not adding each round like it should. So the question is: What is wrong with the code after the while loop?
while ((x != 0) && (suma < Meta)){ cout << "SUM =" << x + last number << endl; if (player == Person) { x = machinerandomnDigit(last number); sum = sum + x; player = Person; last number = x;
I have a program that stores current a low numbers. The Object is to Store the low number every time time one is presented. so say I start the function the first number is the low number. but the trouble im having it once the function is called again it starts over(low number). Is there a way I can keep the function value once the function is called again? Any better way of doing this while keeping function in a class?
double a; class rff{ public: void FGH() { doubleb=0; cout<< "pick a number"<<endl;
Write a C++ program that compares the execution time of the above summation using two different solutions: one that uses loops, and another that uses the closed form approach. Use large values of n for the comparisons, such as, 10^7, 10^8, 10^9, 10^10, 10^11,10^12, 10^13, and 10^14. Provide a comparison table for the execution time in both solutions.Do not worry about the value of the actual sum. Overflow will occur in the sum value rendering it invalid; however, this is not the primary concern of the program. Execution time is the primary concern.
Here is a simplified version of my Menu class, where submenus can be inserted arbitrarily deep. I need to add a new functionality "go back to previous menu", which I would like to be activated by entering 0 (universal command for all Menu instances). I considered the Memento Pattern, but that doesn't seem to quite fit. add that functionality to my Menu class.
#include <iostream> #include <cstring> using namespace std; const int END = -1, NO_SUBMENU = 0;
Say a user installs and uses the software for awhile. Then they uninstall it. Client wants the database containing client data to remain behind, in case they ever re-install the software. Which is fine.
So then.. they re-install the software. Client wants them to have the choice to either use the existing database, or to create a new one. When the software fires up, it always checks for the database, and creates one if it's not there. So how can I determine if the instance is a new install, or a current install, given that the database will be there no matter what?
For my assignment I have to have an array with only zeros.
Code: int a[20] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; Then I need to send it into a function that makes the array like this
Code: int a[20] = {0,1,2,3,4,5,6, ... , 19}
Which I have done here
Code: int initialize(int a[], int n) { int m = 0; int i; printf("
[Code] ....
Now I need to do the following with the array. I need to take whatever value is in each position and add that value to all of the previous values. like this.
Code: a[3] = a[3] + a[2] + a[1] + a[0]
only for every a[i] I know that I can code this the long way, but I just can't see to be able to find out how to do this a better way.
I am making a product and in which i use a timer. I want when the product is being start the timer will run and when the product is off the timer will stop. If i again start the product the timer will start from its previous value.
I have problem that the timer start from its initial when i start my product.
using namespace std; //class declaration class dayType{ public: int presday;
[Code] ....
So everything works perfectly, well not everything lol. Code compiles successfully without any errors but previous day does not calculate. In a sense that when it asks for number of previous days it returns a blank statement.
For example: Previous number day is: shows nothing
Im trying to do a small program that will create multiples of the previous line *2, and spit out the anwser in seperate lines (as many times as the user wants)
Example if i wrote it in a bad way
2 4 8 16 32 etc.
At this time my code looks likes this, now im planing to get my hands on the IF statment
using System; using System.Collections.Generic; using System.Linq;
if (Choice == 2) { cout << "" << endl << "You follow the light to the end of the hallway, you find your self in a room" << endl << "with natural light coming from a hole in the ceiling." << endl << "" << endl << "You hear the door you just came through, slam behind you!" << endl << "" << endl << "There are three possible directions." << endl << "" << endl << "Do you:" << endl << "" << endl << "1) Go forward" << endl << "" << endl << "2) Go left" << endl
[Code] .....
Ignore the if (Choice == 2) at the beginning, that's linked to some previous code.
I want to make the player go back to the first bit of text but i'm not sure how to do this if they keep choosing to go back and forth from one location.
I first thought of doing it by just putting the text back in after they have chosen the option, but I can't do this infinite times.
I'm making my first steps in STL, and I have a few question:
Is there a way to get an iterator to the i'th element in the collection (set or list), instead of just to the end or the begin?
And another question: Let's say I have an iterator, pointing to some element in my collection, and I use erase() (which takes as parameter an iterator that points to the soon-to-be erased element), what happens to that iterator? will it now point to NULL?
Why this code works Elenco e1; e1.add(Persona("a","b")); e1.add(Persona("c","d")); e1.add(Persona("e","f")); e1.add(Persona("e","f")); e1.remove(2); //list of 4 elements
but this not work? Elenco e1; e1.add(Persona("a","b")); e1.add(Persona("c","d")); e1.add(Persona("e","f")); e1.remove(2); //list of 3 elements
This is remove method: Persona Elenco:: remove(int pos){ list<Persona> ::iterator iter=l.begin(); for(int i=0 ;i<pos;i++){ iter++; } return *(l.erase(iter)); //erase ritorna un iterator }
Here's a few parts of a program I'm working at. It does compile, and it does work as expected. Anyway Eclipse Kepler marks one line as a bug with the remark Field 'befehl' could not be resolved. The bug sign didn't show up when both classes were in one file.
ScriptInterpreter maintains and processes a vector of Objects, initialised with example data. An iterator of the vector keeps track of the current position while various methods process the data. I've copied the relevant lines only.
I can live with a few wrongly bug-marked lines in Eclipse. What I don't want is any hidden errors that express at some time later.
Is there anything wrong with the code? Anything that's not recommended and compiles anyway? Is anything c++11-specific about the questionable line?
AtomicCommand.h class AtomicCommand { public: int befehl;
[Code] .....
Note that line 9 has a bug sign, too. Eclipse doesn't recognise all my c++11 code.
I can't seem to make the STL iterator class work how I need it to.I am implementing a multi list graph and I need to iterate through my STL list of Vertex pointer objects. I keep getting the error:
Error 1 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::_List_iterator<_Mylist>' (or there is no acceptable conversion) and the same for != for my terminating condition.
template <typename V, typename E> void Graph<V, E>::InsertEdge(V from, V to, E edge) { list<Vertex<V>*>::iterator iter; for(iter = m_Vertices.begin(); iter != m_Vertices.end(); ++iter)
I just figured out that some std functions (for example: copy) need the resource and target objects have iterators to work. Otherwise, the compiler rejects. In case of two arrays, declared as:
myA[0] is like a pointer, myB.begin() an iterator, if I do not make any mistake. So, what is exactly the difference between the pointer and the iterator here? They all give the access to elements.
If I need the target of copy to be an array like myA which cannot give an iterator, is there a way to make the command "copy" work for it?
I want to get the iterator position after to use find if:
std::list<Texture*>::iterator result = find_if( texturelist.begin(), texturelist.end(), std::bind2nd<CompareTEX>(CompareTEX(),n_tex)); if (result != texturelist.end()) { return // position result }
I am receiving the error: Vector Iterator not incrementable. However, when erasing I'm already re-setting 'it' and pre-incrementing at the end of the while-clause.what's wrong?
We were given a task to use lists and iterators. We were supposed to make them from scratch. I'm done with that. The problems that I'm having are as following:
1. I'm not able to access the list made of Course datatype which is present in each Student instance. Does this mean I need to make an iterator for that course list inside the student class?
2. Similarly since I don't have direct access to The course list so I added the course into the Student list through the student objects not through the iterator. How can I do it through the iterator?
3. Printing of a particular student and his courses is not happening as my iterator made for student only prints out the students, not the courses present in their courselist. How to do that?
Here's the code
#include <iostream> #include <string> using namespace std; const int ILLEGAL_SIZE = 1; const int OUT_OF_MEMORY = 2; const int NO_SPACE = 3; const int ILLEGAL_INDEX = 4;