標題:
[隨堂測驗] 抽籤程式
[打印本頁]
作者:
周政輝
時間:
2018-4-28 13:49
標題:
[隨堂測驗] 抽籤程式
本帖最後由 周政輝 於 2018-4-28 13:50 編輯
發揮創意想想看, 抽籤程式在日生活中甚麼時候可以派上用場呢?
給定一個食物的陣列,裡面的內容物有10樣食物可以吃
請隨機產生一個作為今天晚餐的內容
[attach]3975[/attach][attach]3976[/attach][attach]3977[/attach]
作者:
王駿愷
時間:
2018-4-28 14:06
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
srand(time(NULL));
int food=0;
cout<<"今天晚上吃啥"<<endl;
string a[]={"雞肉","牛排","漢堡","豬腳","義大利麵","鵝肉","鴨肉","法國土司","薯條","炸雞"};
food=(rand()%9)+1;
cout << "今天吃:" << a[food-1] << endl;
system("pause");
return 0;
}
複製代碼
作者:
林峻安
時間:
2018-4-28 14:14
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
int main()
{
srand(time(NULL));
int food=0;
cout<<"抽籤中"<<endl;
cout<<"========="<<endl;
cout<<"今晚吃啥?"<<endl;
string mora[]={"麵","牛肉","漢堡","披薩","炸雞","牛肉飯","奶昔","鵝肉","吐司","豬腳麵"};
food=(rand()%10)+1;
cout <<"吃:"<<mora[food-1]<<endl;
system("pause");
return 0;
}
複製代碼
作者:
湯東緯
時間:
2018-4-28 14:25
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
cout<<"☆★☆抽籤程式☆★☆"<<endl;
int food=0;
string a []={
"豬肉","雞肉","牛肉",
"鴨肉","鵝肉","羊肉",
"漢堡","秋刀魚","鰻魚",
"鮭魚"};
srand(time(NULL));
food=(rand()%10-1)+1;
cout<<"今晚吃啥"<<endl;
cout << "今天吃:" << a[food-1] << endl;
system("pause");
return 0;
}
複製代碼
作者:
吳秉翰
時間:
2018-4-28 14:25
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
srand(time(NULL));
int supper=0;
string food[]={"米飯",
"麵包",
"蛋糕","餅乾","饅頭","麵條","玉米","蕃薯","芋頭","糖果"};
supper=(rand()%(10-1+1)+1);
cout<<"吃"<<food[supper+1]<<endl;
system("pause");
return 0;
}
複製代碼
作者:
戴嘉禾
時間:
2018-4-28 14:26
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
int num = 0;
cout<<"☆★☆抽籤程式☆★☆"<<endl;
cout<<"===================="<<endl;
cout<<"★今天晚上要吃什麼★"<<endl;
string j[]=
{
"豬肉",
"牛肉",
"雞肉",
"羊肉",
"鴨肉",
"泡麵",
"漢堡",
"薯條",
"雞塊",
"餅乾",
};
srand(time(NULL));
num=(rand()%10)+1;
cout<<endl;
cout<<"~今天晚上吃"<<j[num-1]<<"好了~"<<endl;
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
黃安立
時間:
2018-4-28 14:26
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int food =0;
cout<<"今天晚餐吃"<<endl;
string mora[] = {"吃今天晚餐: (1:雞,豬,牛,鵝,漢堡,羊,飯,麵,吐司,豬腳,)"};
food=(rand()%9)+1;
cout << "今天晚餐吃" << endl;
system("pause");
return 0;
}
複製代碼
作者:
鄭楀諺
時間:
2018-5-3 09:33
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
cout << "生" << endl;
_sleep(300);
system("cls");
cout << " 日" << endl;
_sleep(300);
system("cls");
cout << " 快" << endl;
_sleep(300);
system("cls");
cout << " 樂" << endl;
_sleep(300);
system("cls");
cout << "生日快樂" << endl;
_sleep(300);
system("cls");
system("pause");
return 0;
}
複製代碼
作者:
鄭楀諺
時間:
2018-5-5 13:41
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
string food[]={"漢堡","牛排","羊肉爐","意麵","大便","餿水"};
srand(time(NULL));
while(true)
{
cout<<"☆★☆抽籤程式☆★☆"<<endl;
cout<<"今晚吃甚麼?"<<endl;
system("pause");
system("cls");
for(int i=1;i<=30;i++)
{
if(i%2!=0)
{
cout<<"☆★☆抽籤中☆★☆"<<endl;
cout<<food[rand()%6]<<"!";
}
if(i%2==0)
{
cout<<"★☆★抽籤中★☆★"<<endl;
cout<<food[rand()%6]<<"!";
}
_sleep(55+i);
system("cls");
}
cout<<"吃"<<food[rand()%6]<<"!"<<endl;
system("pause");
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2