Go to Post I don't fully buy into the 'we're all winners' concept. That is a broad statement that doesn't really say much. How did we become all winners? What did we do to become winners? Pay an expensive registration fee and participate in a robotic competition? - JaneYoung [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 07-12-2011, 20:29
Any Mouse's Avatar
Any Mouse Any Mouse is offline
Registered User
FRC #3145 (TeraViks)
Team Role: Programmer
 
Join Date: Dec 2011
Rookie Year: 2011
Location: Unova
Posts: 6
Any Mouse is an unknown quantity at this point
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.
Reply With Quote
  #2   Spotlight this post!  
Unread 07-12-2011, 20:46
plnyyanks's Avatar
plnyyanks plnyyanks is offline
Data wins arguments.
AKA: Phil Lopreiato
FRC #1124 (The ÜberBots), FRC #2900 (The Mighty Penguins)
Team Role: College Student
 
Join Date: Apr 2010
Rookie Year: 2010
Location: NYC/Washington, DC
Posts: 1,114
plnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond repute
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
}
You'll need a variable to store the running count, and after the user presses enter, it'll have to be incremented. Does that snippet make sense logically?
__________________
Phil Lopreiato - "It's a hardware problem"
Team 1124 (2010 - 2013), Team 1418 (2014), Team 2900 (2016)
FRC Notebook The Blue Alliance for Android

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
Reply With Quote
  #3   Spotlight this post!  
Unread 07-12-2011, 20:56
Andrew Lawrence
 
Posts: n/a
Re: Press Enter to Add One

Quote:
Originally Posted by plnyyanks View Post
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
    cout << "Count: " << count << endl; //show count to user
}
You'll need a variable to store the running count, and after the user presses enter, it'll have to be incremented. Does that snippet make sense logically?
Trust Phil. He knows this stuff.
Reply With Quote
  #4   Spotlight this post!  
Unread 07-12-2011, 21:18
plnyyanks's Avatar
plnyyanks plnyyanks is offline
Data wins arguments.
AKA: Phil Lopreiato
FRC #1124 (The ÜberBots), FRC #2900 (The Mighty Penguins)
Team Role: College Student
 
Join Date: Apr 2010
Rookie Year: 2010
Location: NYC/Washington, DC
Posts: 1,114
plnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond repute
Re: Press Enter to Add One

Quote:
Originally Posted by SuperNerd256 View Post
Trust Phil. He knows this stuff.
Thanks Andrew, I try.
__________________
Phil Lopreiato - "It's a hardware problem"
Team 1124 (2010 - 2013), Team 1418 (2014), Team 2900 (2016)
FRC Notebook The Blue Alliance for Android
Reply With Quote
  #5   Spotlight this post!  
Unread 07-12-2011, 21:41
calcmogul's Avatar
calcmogul calcmogul is offline
WPILib Developer
AKA: Tyler Veness
FRC #3512 (Spartatroniks)
Team Role: Mentor
 
Join Date: Nov 2011
Rookie Year: 2012
Location: Santa Maria, CA
Posts: 52
calcmogul is just really nicecalcmogul is just really nicecalcmogul is just really nicecalcmogul is just really nice
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;
}
std:: needs to be added to the front of STL functions like cout unless you specify "using namespace std;" at the top of the program.
Reply With Quote
  #6   Spotlight this post!  
Unread 08-12-2011, 18:59
Any Mouse's Avatar
Any Mouse Any Mouse is offline
Registered User
FRC #3145 (TeraViks)
Team Role: Programmer
 
Join Date: Dec 2011
Rookie Year: 2011
Location: Unova
Posts: 6
Any Mouse is an unknown quantity at this point
Thumbs up Re: Press Enter to Add One

Thanks that was very helpful.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

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


All times are GMT -5. The time now is 15:01.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi