|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Press Enter to Add One
I am new to c++ programing and am want to make a program in which if you press enter a number will increase by one. I can make the doesprogram loop and recognize 'enter', but when I try to put them together it doesn't work. Please help.
|
|
#2
|
|||||
|
|||||
|
Re: Press Enter to Add One
Try something like this:
Code:
//make sure you #include <iostream>
int count = 0; //variable to store count
while(count < 10){ //this will only run 10 times
system("pause"); //wait for user to press enter - this will send the Windows shell command "pause", and wait for the user to press enter
count++; //increment count
std::cout << "Count: " << count << endl; //show count to user
}
Last edited by plnyyanks : 07-12-2011 at 21:47. Reason: forgot "std::" - good catch. or, put "using namespace std;" at the top of the program |
|
#3
|
|||
|
|||
|
Re: Press Enter to Add One
Quote:
![]() |
|
#4
|
|||||
|
|||||
|
Re: Press Enter to Add One
|
|
#5
|
||||
|
||||
|
Re: Press Enter to Add One
You can write this with a for loop too, which has variable incrementing built in:
Code:
#include <iostream> //has cout
for ( int count = 1 ; count <= 10 ; count++ ) {
system("pause"); //waits for user to press enter
std::cout << "Count: " << count << std::endl;
}
|
|
#6
|
||||
|
||||
|
Thanks that was very helpful.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|