fork download
  1. /* HIGH/LOW GAME */
  2. #include<iostream.h>
  3. #include<conio.h>
  4. #include<stdlib.h>
  5. /*
  6. This program plays a simple game.The computer picks a random number
  7. from
  8. 0 to 100, and the user tries to guess the number.
  9. */
  10. const int totchan=7;
  11. void main()
  12. {
  13. int number; //the computer's random number
  14. int guess; //the user's guess
  15. int chances=0,score=0,chanscor; //chanscor stores score for 1
  16. successful chance.
  17. char ans;
  18. do
  19. { clrscr();
  20. chances=score=0;
  21. cout<<"
  22. Welcome to the High/Low game.";
  23. cout<<"
  24. I will pick a random number from 0 to 100.";
  25. cout<<"
  26. You must try to guess the number.
  27. ";
  28. randomize();
  29. number=(int)(rand()%100);
  30. chanscor=100/totchan; //score for each successful chance
  31. do
  32. {
  33. cout<<"
  34. What is your guess? (0 to 100) ";
  35. cin>>guess;
  36. if((guess<0)||(guess>100))
  37. {
  38. cout<<"Sorry, but your guess "<<guess<<"must be from 0 to 100.";
  39. }
  40. else if(guess < number)
  41. {
  42. cout<<guess<<" is low.Try a higher number.";
  43. }
  44. else if(guess > number)
  45. {
  46. cout<<guess<<" is high.Try a lower number.";
  47. }
  48. else //if correct number is guessed
  49. { //number is correct, and the "do" loop will end below
  50. cout<<guess<<" is correct. Congratulations!";
  51. score=chanscor*(totchan-chances); //score calculated for number of
  52. chances left
  53. cout<<"
  54. Your score is "<<score<<endl;
  55. break;
  56. }
  57. chances++;
  58. if(guess!=number)
  59. cout<<"
  60.  
  61. Now you have "<<totchan-chances<<"chances left."<<endl;
  62. if(chances==totchan)
  63. { cout<<"
  64.  
  65. Only "<<totchan<<"chances are allowed.Better luck next
  66. time";
  67. cout<<"
  68. The actual number was "<<number<<endl;
  69. break;
  70. }
  71. }while (guess!=number);
  72. cout<<"
  73.  
  74. Thank you for playing High/Low!";
  75. cout<<"Want to play it again? (y/n)...";
  76. cin>>ans;
  77. }while(ans=='y' || ans=='Y');
  78. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:21: fatal error: iostream.h: No such file or directory
 #include<iostream.h>
                     ^
compilation terminated.
stdout
Standard output is empty