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",

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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.