Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <conio.h>
  2. #include <stdio.h>
  3. #include <time.h>
  4. #include <iostream>
  5. using namespace std;
  6. int main()
  7. {
  8.          
  9.     clock_t t_ini, t_fin;
  10.     clock_t t_ini2, t_fin2;
  11.     double tespera,nletra,secs,secs2;
  12.     char letra,x;
  13.     int N=0;
  14.     float tms=0,n,media=0;
  15.  
  16.     cout<<"Solo tienes que teclear lo que veas por pantalla"<<endl<<"--> Asegurate de que BLOCK MAYUS esta OFF <--"<<endl<<"Cuando estes listo introduce el numero de pruebas para comenzar: ";
  17.     cin>>n;
  18.     cout<<endl<<endl;
  19.     if (n<=0) {
  20.              cout<<"n=1 para evitar errores";
  21.              n=1;
  22.              }
  23.     while (N<n)
  24.     {
  25.           N++;
  26.   t_ini = clock();
  27.   srand (clock());
  28. tespera = rand()%50;
  29. tespera= tespera/10;
  30. nletra = rand()%25;
  31. nletra=nletra+97;
  32. letra=char(nletra);
  33. do {
  34.     t_fin = clock();
  35.     secs = (double)(t_fin - t_ini) / CLOCKS_PER_SEC;
  36. } while(secs<tespera);
  37. printf("%c", letra);
  38.  t_ini2 = clock();
  39.  while(x!=letra){
  40.  x=getch();
  41. }
  42.  
  43. t_fin2 = clock();
  44. secs2 = (double)(t_fin2 - t_ini2) / CLOCKS_PER_SEC;
  45. printf(" --> %.16g milisegundos\n\n", secs2 * 1000.0);
  46. tms=tms+secs2;
  47.  
  48. }
  49. media=1000*tms/n;
  50. cout<<endl<<endl<<"Tu media es de: "<<media<<"ms. Pulsa cualquier tecla para salir.";
  51. cin>>n;
  52.  
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement