1,105,594 Community Members

Help! Can someone check this codes?

Member Avatar
cheers07
Newbie Poster
5 posts since Mar 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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",
Member Avatar
Moschops
Nearly a Posting Virtuoso
1,386 posts since Sep 2008
Reputation Points: 414 [?]
Q&As Helped to Solve: 269 [?]
Skill Endorsements: 16 [?]
Featured
 
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);
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: