[問題] 做完報告,想請高手指點一下
各位先進,這是我的作業,如果冒犯大家請告訴我,我會盡快撤下
這是一個迷你的高爾夫球遊戲,我東拼西湊的做完了
可是有些指令我卻不是很了解他的用途
#include <cmath>
#include <ctime>
上面這兩個我不放好像就不能跑
srand ( static_cast <int>(time(NULL)) ) (是來讓隨機數更亂的嗎?不明白放哪最適當)
toupper和tolower的不同?
還有我的作業要怎麼寫才能更有效率或是更漂亮呢?
希望前輩能指點我一下
=================================以下是作業======================
#include<iostream>
#include <cmath>
#include <ctime>
using namespace std;
int main()
{
char club = ' ';
int distance = 280;
int par = 0;
int distanceHit = 0;
//enter input data
cout << " CP1200 GOLF GAME 2008" << endl;
cout << " By Wei Chih Chen" << endl;
cout << "The hole is a par 5 and is 280 meters in length." <<endl;
cout << "You may use a driver, iron, or a putter." << endl;
cout << "The average distance each club can hit is: " << endl;
cout << "Driver = 100m, Iron = 30m, Putter = 10m. " << endl;
cout << " START GAME" << endl;
cout << endl;
srand ( static_cast <int>(time(NULL)) );
do //start loop
{
cout << "You are " << distance <<" metre/s from the hole, after " << par <<
" stroke/s." << endl;
cout << "Please select [ (D)river-100m, (I)ron-30m, (P)utter-10m ]: ";
cin >> club;
club = toupper(club);
par++;
if(club == 'D')
{
distanceHit = rand()%(120 - 80 + 1) + 80;
}
else if (club == 'I')
{
distanceHit = rand()%(36 - 24 + 1) + 24;
}
else if (club == 'P')
{
distanceHit = rand()%(12 - 8 + 1) + 8;
}
else
{
distanceHit = 0;
cout << endl;
cout << "Invalid club selection... Air Swing!";
}
//end if
cout << endl;
distance = distance - distanceHit;
cout <<"You hit "<< distanceHit << " metres ..." << endl;
if (distance < 0)
{
distance = distance * -1;
}
else
distance = distance;
}while (distance != 0); //end while
cout << endl;
cout << "Clunk... The ball is in the hole." << endl;
if (par > 5) //judge the score
{
int num = 0;
num = par - 5;
cout << "Congratulations. You are " << num << " over par.";
}
else if (par < 5)
{
int num = 0 ;
num = 5 - par;
cout << "Disappointing. You are " << num << "under par.";
}
else
{
cout << "Well done. You have achieved par.";
}
system("pause");
return 0;
}//end of main function
--
http://blog.roodo.com/liarboo
內有相機經驗分享
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.243.147.175
推
05/08 00:39, , 1F
05/08 00:39, 1F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章