#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;
}
Why isn't this working the way I wan't it to?(C++)
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.
The first problem is when your using cin on count you are overwritting the value of count.
define:
char somevar;
cin >> somevar;
instead.
define:
char somevar;
cin >> somevar;
instead.
try system("PAUSE"); which works in windows though I'm uncertain the system command in other operating systems
ah, i just tested that your right....*Smacks self in face..* int = integer duh!
So what would I store it in if I wanted it to do a space?
So what would I store it in if I wanted it to do a space?
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)
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?
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement