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;
I'm creating a program that is based on a menu system. Basically each menu is its own user-defined function. The problem is at each menu you can input 'b' to go to the previous menu. I just have it call the function of that menu.
However, do the functions need to complete themselves eventually? If I just keep calling functions will I just keep going further and further deeper into ever running functions?
If so how do I avoid this and yet keep the option to go back to a previous menu/function?
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 new here! I just wanted to ask, how can I go back to Main menu using this code that I have made (I know it's not yet finish I'm using Visual Studio c++ 2010! I there are any errors in my codes
Project: Computer Shop System
#include <iostream> #include <string> using namespace std; int pcnum[5],x; //choice pc int pc; int i; //name int y; //hours
I am trying to write a menu program that will be broken down into a series of calls to function for each of the menu items. Two of the menu items will be simple programs which I wrote.
I want two of the functions to run one of the two programs I am trying to include as items in the menu.
So far I am only familiar with variables, loops, if statements, and I just learned how to write functions.
The problem I am have is that I don't quite understand how to write a function that will run one of the two programs. Also I am having a hard time writing the program in away that would allow the user to select the menu items.
This is what I have so far, it gives me a nice menu to select from and it all works but after I make a selection it closes the program. I tried to return to it but it won't work for me
#include <stdio.h> int main() { int choice; int deposit; int balance = 500; { printf(" CHOOSE FROM THE FOLLOWING
I have two menu items. When item 1 is disabled, I want item 2 to be disabled as well. In the OnUpdate handler of menu item 1, I have tried to use "t_pMenu = pCmdUI->m_pMenu;", "t_pMenu = pCmdUI->m_pSubMenu;" and "t_pMenu = pCmdUI->m_pParentMenu;" but I always get NULL t_pMenu. How can I achieve this purpose?
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?
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;
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 we use bitwise-shift to shift all bits to the right by 2, x is 0:
00000000000000000000000000000000
If we then do a bitwise leftshift on x by 30, do we end up with:
11000000000000000000000000000000 or 00000000000000000000000000000000
In other words, when we perform right shift which clips away the least most significant bits, and then do a left shift, is it possible for those bits to reappear?
I am trying to use push back in a 2D vector but I don't know how to. This is what I have:
vector <vector <BigInt> > matr;
for (BigInt i=0;i<rij;i++) { for (BigInt j=0;j<kolom-1;j++) { matr.push_back().push_back((i+1)^(pow-j)); } }
I quickly invented something but that doesn't work obviously. it should be equivalent to this: (the only problem in the code below is that those indexes don't exist yet that's why I need push_back())
for (BigInt i=0;i<rij;i++) { for (BigInt j=0;j<kolom-1;j++) { matr[int(i)][int(j)]=(i+1)^(pow-j); } }
Code: class moClassValueContainer { public: moClassValueContainer(); moClassValueContainer(string,int); [Code] ....
In my main.cpp, I have blow loop
Code: for (xml_node tnode = it->first_child(); tnode ; tnode = tnode.next_sibling()) { Container tmpContainer(tnode); if (tmpContainer.getType() == SINGLE) { string t = tmpContainer.getName();
[Code] ....
I cannot push_back(t). I examined the code with debugger, t has correct string value assigned, but even after 20-30 iterations, there is no element for headerFields vector.
I am writing another program and I cannot find for the life of me how to loop the program back to the start of a function.
Code: #include <stdio.h> #include <stdlib.h> int main(void) { int choice; char band1, band2, band3, band4; printf ("This program calculates the resistor value based on the colours of the wire. (enter the integer near the command) "); printf ("What would you like to do?
[Code].....
This is my current iteration of the program. Obviously, I haven't finished writing the case 1 of the first switch, but for the other ones. I thought that return main would cause the program to loop back to the beginning after executing the case, but I see that it is not the case (pun not intended). Anyways, what would I have to insert to cause the program to loop again (other than for case 3)? And another question, why is it that in scanf in the first case, the program only accepts two characters before finishing?
I have a device that have some communication protocols and it will respond and send some specific data when somebody communicates with the device. I tried to build a C code that will send those protocols to the device and then store those sending data. Now I don't understand that how to send those commands. Other things than that I can manage with the file handling programming.Is there any predefined function using which it will send some specific data or something like that??
I am trying to get all these functions work together and send the value of countX and countY back into main from function2() and function3() to be used by function4() later on.. But I keep getting 0 printed out and I am not quite sure why.
Code:
#include<stdio.h> #include<stdlib.h> #include<time.h> #define maxrow 20 //defines maxrow as a constant of 20 #define maxcol 30 //defines maxcol as a constant of 30 }