Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   simple error (http://www.programmingforums.org/showthread.php?t=8693)

Quagmire Mar 3rd, 2006 10:05 AM

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:

Polyphemus_ Mar 3rd, 2006 10:22 AM

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.

Quagmire Mar 3rd, 2006 10:23 AM

yeah i usually make people mad. thanks

Infinite Recursion Mar 3rd, 2006 10:34 AM

This looks wrong to me...

while (numcheck = 0)

shouldn't it be...

while (numcheck == 0)

Quagmire Mar 3rd, 2006 10:44 AM

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

DaWei Mar 3rd, 2006 11:00 AM

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.

snipertomcat Mar 3rd, 2006 7:31 PM

Yea man...do it again and your hands will be chopped off.

Bench Mar 3rd, 2006 8:40 PM

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


Eric the Red Mar 3rd, 2006 8:47 PM

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;
}

DaWei Mar 3rd, 2006 9:01 PM

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.


All times are GMT -5. The time now is 9:14 AM.

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