| | |
Pressing a Button makes a new thing
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2009
Posts: 186
Reputation:
Solved Threads: 0
if I get this down, then I'll complete my assignment.
I want my program to have the ability that whoever is using the program has the ability to control how many customers a restaurant has.
Say Pressing C = new customer.
And depending on how many times they press c, they should have a number associate them with it.
Say he types in CCC, then the first C should have a 1, and the second should have a 2, and the third should have a 3.
Say you have the structs, and etc.
And we're not in the main.
but all this does, when compile is output a series of 111111111111111
I want my program to have the ability that whoever is using the program has the ability to control how many customers a restaurant has.
Say Pressing C = new customer.
And depending on how many times they press c, they should have a number associate them with it.
Say he types in CCC, then the first C should have a 1, and the second should have a 2, and the third should have a 3.
Say you have the structs, and etc.
And we're not in the main.
char action;
cout<<"how many?";
cin>>action;
if(sub_choice(action))
{
while (action == 'C')
{
Customer *CUST = new Customer;
int count = 1;
CUST->lineNumber = count;
count++;
CUST = CUST-> next;
}
}but all this does, when compile is output a series of 111111111111111
•
•
Join Date: Apr 2009
Posts: 186
Reputation:
Solved Threads: 0
char action;
cout<<"how many?";
cin>>action;
if(sub_choice(action))
{
int count = 1;
Customer *head = NULL;
while (action == 'C')
{
head = CUST;
Customer *CUST = new Customer;
CUST->lineNumber = count;
count++;
CUST = CUST->next;
}
}would that fix the memory leak?
also, how can I stop the infinite loop @_@
>would that fix the memory leak?
No
>also, how can I stop the infinite loop
use the
By the way:
No
>also, how can I stop the infinite loop
use the
break statement 
By the way:
Customer *head = NULL; is a very dangerous instruction, you're assigning a value to an unknown memory address
Last edited by tux4life; May 10th, 2009 at 3:28 pm.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
C++ Syntax (Toggle Plain Text)
char action; cout<<"how many?"; cin>>action; if(sub_choice(action)) { while (action == 'C') { Customer *CUST = new Customer; int count = 1; CUST->lineNumber = count; count++; CUST = CUST-> next; } }
And a memory leak because you dont delete the variables created by the NEW STATEMENT.
So Heres the thing.
THink user types 'ccc'
you read 'c' so now the input stream has 'cc' left in it.
Then you are running the while loop.
only depending upon the first 'c';
SO what do you do to take in the second and third 'c' left in the input stream?
So if I didn't misunderstand you, you want:
- let the user press the 'c'-key on his keyboard and count the number of times the 'c'-key was pressed
- create an array of structures with as it's upper bound the number of times the 'c'-key was pressed
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
![]() |
Similar Threads
- computer revs when holding start button (Troubleshooting Dead Machines)
- How do you load a code from pressing another button? (Pascal and Delphi)
- please help computer will not start (Troubleshooting Dead Machines)
- Frequent "Page cannot be..." and slow performance. Please read. (Viruses, Spyware and other Nasties)
- Gigabyte 939 (Motherboards, CPUs and RAM)
- repeating the whole program after pressing Yes button in the confirmation message box (Java)
- need feedback on my new flash site (Website Reviews)
- More Printer Problems (USB Devices and other Peripherals)
Other Threads in the C++ Forum
- Previous Thread: I got stuck on loading the matrix from file
- Next Thread: A problem with dynamic allocation..help please
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






