![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2006
Location: Ohio
Posts: 22
Rep Power: 0
![]() |
simple error
#include <iostream.h>
main() { int numcheck, number, guessnum, guesscounter; while (numcheck = 0) { cout << "Enter a number between 1 and 100\n"; cin >> number; numcheck=0; if (number < 1) { numcheck = 1; } if (number > 100) { numcheck = 1; } } return 0; } the window pops up but then closes before you can do anything Can someone help me please. :banana: |
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4
![]() |
Initialize numcheck to zero:
main() {
nt numcheck, number, guessnum, guesscounter;
numcheck = 0;
while( . . .and read the forum rules, it clearly states you should use code tags. |
|
|
|
|
#3 |
|
Newbie
Join Date: Feb 2006
Location: Ohio
Posts: 22
Rep Power: 0
![]() |
yeah i usually make people mad. thanks
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
This looks wrong to me...
while (numcheck = 0) shouldn't it be... while (numcheck == 0)
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
#5 | |
|
Newbie
Join Date: Feb 2006
Location: Ohio
Posts: 22
Rep Power: 0
![]() |
Quote:
|
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Maybe if you got with the program and didn't act like you have rice for gray matter, people wouldn't "get mad at you". You've certainly heard enough about the use of code tags. If you figure out a problem, as you say you did with IR's suggestion, post back so people won't continue to waste time on something you've fixed.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
#7 |
|
Programmer
Join Date: Nov 2005
Location: Spring Valley, CA
Posts: 52
Rep Power: 3
![]() |
Yea man...do it again and your hands will be chopped off.
|
|
|
|
|
#8 | |
|
Newbie
Join Date: Feb 2006
Posts: 20
Rep Power: 0
![]() |
Quote:
std::cin.get(); // add this at the end of your program just before your return statement // your program will finish when you press the return key |
|
|
|
|
|
#9 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
easy solution
Are u using dev-c++ welll anyways just add this to the top of your file
#include <stdlib.h> and then use system("Pause"); // right before end of main example ****** #include <stdlib.h> #include <iostream.h> int main() { system("Pause"); return 0; } |
|
|
|
|
#10 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Bench's method is portable across systems, Eric's is not. The phenomenon, which is one of the most commonly asked questions about C/C++, is not Windows specific. Programs close when they finish. If you don't want them to finish before your eyeballs are through with the display, request user input. Deprive the program of that input until your eyeballs are through.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|