Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Closed Thread
 
Thread Tools Display Modes
Old Mar 3rd, 2006, 9:05 AM   #1
Quagmire
Newbie
 
Quagmire's Avatar
 
Join Date: Feb 2006
Location: Ohio
Posts: 22
Rep Power: 0 Quagmire is an unknown quantity at this point
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:
Quagmire is offline  
Old Mar 3rd, 2006, 9:22 AM   #2
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
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.
Polyphemus_ is offline  
Old Mar 3rd, 2006, 9:23 AM   #3
Quagmire
Newbie
 
Quagmire's Avatar
 
Join Date: Feb 2006
Location: Ohio
Posts: 22
Rep Power: 0 Quagmire is an unknown quantity at this point
yeah i usually make people mad. thanks
Quagmire is offline  
Old Mar 3rd, 2006, 9:34 AM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline  
Old Mar 3rd, 2006, 9:44 AM   #5
Quagmire
Newbie
 
Quagmire's Avatar
 
Join Date: Feb 2006
Location: Ohio
Posts: 22
Rep Power: 0 Quagmire is an unknown quantity at this point
Quote:
Originally Posted by Infinite Recursion
This looks wrong to me...

while (numcheck = 0)

shouldn't it be...

while (numcheck == 0)
yah I figured that out. thanks anyways
Quagmire is offline  
Old Mar 3rd, 2006, 10:00 AM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline  
Old Mar 3rd, 2006, 6:31 PM   #7
snipertomcat
Programmer
 
snipertomcat's Avatar
 
Join Date: Nov 2005
Location: Spring Valley, CA
Posts: 52
Rep Power: 3 snipertomcat is on a distinguished road
Yea man...do it again and your hands will be chopped off.
snipertomcat is offline  
Old Mar 3rd, 2006, 7:40 PM   #8
Bench
Newbie
 
Join Date: Feb 2006
Posts: 20
Rep Power: 0 Bench is on a distinguished road
Quote:
Originally Posted by Quagmire
the window pops up but then closes before you can do anything
Can someone help me please. :banana:
My guess is that you are a Windows user, and problem has nothing to do with C++ ... windows automatically closes console windows when a console program is finished... The easy solution - don't let your program finish until you ask it to..
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
Bench is offline  
Old Mar 3rd, 2006, 7:47 PM   #9
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
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;
}
Eric the Red is offline  
Old Mar 3rd, 2006, 8:01 PM   #10
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline  
Closed Thread

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:04 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC