- Pages:
- 1
- 2
| How do I get this to not close automatically; have this code that i can't use cin.get | |
|---|---|
| Topic Started: Apr 8 2009, 09:19 AM (351 Views) | |
| SheWasAlmost18 | Apr 8 2009, 09:19 AM Post #1 |
|
This code uses cin >> value so when i put cin.get() somewhere else, it closes automatically, without me typing in a value
how do I change this code, so i can see what happens if i put a value Edited by SheWasAlmost18, Apr 8 2009, 09:19 AM.
|
| We are made kind by being kind | |
![]() |
|
| Samael88 | Apr 8 2009, 10:19 AM Post #2 |
|
First of all I just want to say that you don't even need the "using namespace std;" here, if you are going to use it, why don't you just put it right after the includes? That way you are using it for the whole thing. I would put a "cin" right before the return, that way you would cause the program to halt there. Else you can include "conio.h" and use a "getch();" instead, that works also The easiest would be this: "cin>>a;" and just declare "a" as a integer that you never use or something. |
![]() |
|
| MMZJSFMMX10MM | Apr 8 2009, 03:10 PM Post #3 |
|
Depending on what you are trying to do you may have to put the cin.get() twice. Once to flush an extra return key and then the second to do what it was you originally wanted it to do. |
![]() ![]()
| |
![]() |
|
| SheWasAlmost18 | Apr 8 2009, 07:40 PM Post #4 |
|
hmm, instead of using cin.get() i used system("PAUSE") It works, but the it says press any key to continue also how do I make a number random like: random int f between 1 and 10 cout<< "You lost " << f << " dollars" << endl; and if i want to say, pick a random number 1-10 they put 3, ( i want 7) how do i say no, and yes Edited by SheWasAlmost18, Apr 8 2009, 07:44 PM.
|
| We are made kind by being kind | |
![]() |
|
| MMZJSFMMX10MM | Apr 9 2009, 12:26 AM Post #5 |
|
You link the random generator with the system clock. I even used "system("pause");" but it is important to note that "system("pause");" is not a good programming technique in C++ under most conditions. Edited by MMZJSFMMX10MM, Apr 9 2009, 12:27 AM.
|
![]() ![]()
| |
![]() |
|
| SheWasAlmost18 | Apr 10 2009, 07:36 PM Post #6 |
|
cool!, how do I get it to display yes when it's the right int, and no if it's not also, *off topic* I have a converter ( oz to lbs) and it works, but how do i get it to not close right after the first number I give it
Edited by SheWasAlmost18, Apr 10 2009, 07:40 PM.
|
| We are made kind by being kind | |
![]() |
|
| Darksorrow131 | Apr 11 2009, 12:55 AM Post #7 |
|
Wrap the question/answer code in an infinite loop ( while(true) { ... } ) and it will keep asking for more numbers. You probably want to break the loop if the user types "quit" or something though. No idea about making the program pause, I've always been running those programs in Command Prompt so this issue never came up
|
|
(let loop () (loop)) ((lambda (x) (x x)) (lambda (x) (x x))) (let ((k #f)) (call/cc (lambda (cc) (set! k cc)) (k)) ((call/cc call/cc) (call/cc call/cc)) -- Infinite loops are awesome! -- Tell me if you have other awesome infinite loops! | |
![]() |
|
| MMZJSFMMX10MM | Apr 11 2009, 02:24 AM Post #8 |
|
To make it pause you can use a random variable like a char and then insert cin >> char; where you want it to pause. The person just has to push enter to continue then. You can also you can use a variable to hold your random number like this:
|
![]() ![]()
| |
![]() |
|
| Cosmic_AC | Apr 11 2009, 12:59 PM Post #9 |
|
To make something repeat until the user wants to quit, use a loop: char cont; do{ /**/// Actions /**/cout << "Continue? (Y/N) : "; /**/cin >> cont; }while(cont != 'y' && cont != 'Y'); If you want to be even more elaborate/precise, you can use another loop to make sure the user enters either 'Y' or 'N': char cont = 'n'; do{ /**/// Actions /**/do{ /******/cout << "Continue? (Y/N) : "; /******/cin >> cont; /**/}while(cont != 'Y' && cont != 'y' && cont != 'N' && cont != 'n'); }while(cont != 'y' && cont != 'Y'); Edited by Cosmic_AC, Apr 11 2009, 01:02 PM.
|
| ++++++++++[>+++++++>+++++++++++<<-]>---.>+.++++.------.----.------.<<++++[>>+++++++<<-]>>.<---.+++. | |
![]() |
|
| SheWasAlmost18 | Apr 11 2009, 07:23 PM Post #10 |
|
I don't quite understand how to apply the loop thing to my converter, but the random guessing thing i'll definitely work on! thanks |
| We are made kind by being kind | |
![]() |
|
| 1 user reading this topic (1 Guest and 0 Anonymous) | |
| Go to Next Page | |
| « Previous Topic · Application Programming Support · Next Topic » |
- Pages:
- 1
- 2









10:38 PM May 18