fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. void main()
  8.  
  9. {
  10. cout << "猜數字 ─ 請猜 1 ~ 5 之中的隨機數"
  11. << endl << endl << endl
  12. << "請輸入數字 = ";
  13.  
  14. int random01;
  15. srand(time(NULL));
  16. random01 = 1 + rand() % (5 - 1 + 1);
  17.  
  18. int num01;
  19. cin >> num01;
  20. if (num01 == random01)
  21. {
  22. cout << endl
  23. << "您好厲害,一猜就中!!!"
  24. << endl << endl << endl;
  25. }
  26. else
  27. {
  28. cout << endl
  29. << "您猜錯了,還有一次機會喔!"
  30. << endl << endl
  31. << "請輸入數字 = ";
  32. int num02;
  33. cin >> num02;
  34. if (num02 == random01)
  35. {
  36. cout << endl
  37. << "您猜對了,恭喜!!"
  38. << endl << endl << endl;
  39. }
  40. else
  41. {
  42. cout << endl
  43. << "您還是沒猜中...下次加油囉!"
  44. << endl << endl << endl;
  45. }
  46. }
  47.  
  48. system("PAUSE");
  49.  
  50. }
  51.  
  52.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:7: error: ‘::main’ must return ‘int’
prog.cpp: In function ‘int main()’:
prog.cpp:48: warning: ignoring return value of ‘int system(const char*)’, declared with attribute warn_unused_result
stdout
Standard output is empty