We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,379 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Help! Can someone check this codes?

We need to combine this two codes to create a game in which we have to count how many times we pressed enter for a matter of time. we need to display the instructions above and how many times we hit or pressed the enter button and also the time.

#include <iostream>
#include <stdio.h>
#include <time.h>
#include <conio.h>
using namespace std;


int main ()
{
 while(_kbhit() )
{
   int c = getche();
   int counter = 0;

   if( c == '\n', counter++ )
   {
      printf("got one\n"); [COLOR="Green"]// but instead of this one we need to show the counter
                           // which we dont know how we can declare it. [/COLOR]  
   }
}
int main ()
{

time_t start,end; // start time and end time

int score=0;
char ans[10];
int ctr;


time (&start); //start timer


printf("GO!");

while(_kbhit() )
{
   int c = getche();
   if( c == '\n' )
   {
      printf("got one\n");
   }
    cout<<"\n";
ctr++;
cout<<ctr; 
}

int minutes = 1 ;
while ( timer < (minutes * 60 )) // convert minutes to seconds
{
printf("");
scanf("%s", &ans);
getchar() ; // for the extra new line because of scanf()

if (strcmp(ans, "hello") == 0)
score++;

if (strcmp(ans, "goodbye") == 0)
score++;


time (&end);
timer = difftime (end,start);

} //end while 


puts("Time Up!");

printf("score is %d over 2",
2
Contributors
1
Reply
3 Hours
Discussion Span
2 Years Ago
Last Updated
2
Views
cheers07
Newbie Poster
5 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

You are using the variable counter to store how many times the button has been pushed. You can display this value with the printf command:

printf("%i ", counter);
Moschops
Practically a Posting Shark
890 posts since Sep 2008
Reputation Points: 297
Solved Threads: 170
Skill Endorsements: 5

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0550 seconds using 2.67MB