Jump to content
  • Advertisement
Sign in to follow this  
DeathsBargin

Why isn't this working the way I wan't it to?(C++)

This topic is 4693 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int count;
    count = 1;
    
    
    cout<<"Please press ENTER to begin counting."<<endl;
    cin>>count;
    while (count <= 25) {
          cout<<"PRESS ENTER" <<endl;
          cout<< count <<endl;
          cin>>count;
          count ++;
          }
    system("PAUSE");
    return EXIT_SUCCESS;
}

I want it to show you count and then ask you to press enter, after you press enter count should go up by one, display this, and then display, repeat the process till we get to 25. But it won't display anything...

Share this post


Link to post
Share on other sites
Advertisement
The line "cin >> count;" means input an integer into count. So it will say "Please press ENTER to begin counting." then wait for you to enter an integer(not just an enter) before continuing.

Share this post


Link to post
Share on other sites
The first problem is when your using cin on count you are overwritting the value of count.

define:

char somevar;
cin >> somevar;


instead.

Share this post


Link to post
Share on other sites
try system("PAUSE"); which works in windows though I'm uncertain the system command in other operating systems

Share this post


Link to post
Share on other sites
Quote:
Original post by ChaosX2
The first problem is when your using cin on count you are overwritting the value of count.

define:

char somevar;
cin >> somevar;


instead.


I didn't find any problems other than i need to press and int instead of space..(And obviously thats not what I want)

Share this post


Link to post
Share on other sites
Quote:
Original post by DeathsBargin
I want it to show you count and then ask you to press enter, after you press enter count should go up by one, display this, and then display, repeat the process till we get to 25.


(a) what happens when you type "24[return]" at the prompt?

(b) what happend when you type "0[return]" at the prompt?

(c) what happens when you type "x[return]" at the prompt?

Share this post


Link to post
Share on other sites
std::cin.get();

may work, though I think you need to actually enter a character there as well... if you have access to conio.h with your compiler you can use while(!kbhit()){;}

__
edit:
a space is most DEFINITLY a char. It may not store it when expecting input, but you can certainly do this to store a char:

char ch = ' ';

my answer was cheeky but correct to your original question.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!