guessnumbergame.cpp

/*************************************************************************** * Copyright (C) 2011 by iceast * * iceast.st@gmail.com * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <ctime> #include <iostream> #include <cstdlib> #include <cmath> using namespace std; int main(int argc, char *argv[]) { int mylist[10]; int thelist[10]; int list[200]; int listlength = 0; int my = 0; cout << "welcome to the Guess Number Math Game" << endl; cout << "It's made by iceast." << endl; cout << "my E-mail is iceast.st@gmail.com" << endl; cout << "If you like it or find a bug for the program please send a e-mail for me." << endl; cout << "you will find the rules in www.lanhaiteam.com" << endl; cout << "Thank You" << endl; cout << "have fun." << endl; cout << ". of the number is right and the site is right too" << endl; cout << "o of the number is right but the site is wrong" << endl; for(;;) { int right = 0; int eight = 0; cout << "please enter a number for the number length:"; cin >> listlength; if (!((listlength < 11) && (listlength > 0))) { cout << "WOW the nubber is wrong! we will chenge it smaller how about 4?"<<endl; listlength = 4; } srand(unsigned(time(0))); for (int i = 0;i<200;i++) { list[i]=rand()%10; } for (int i = 0,y = 0; y < listlength ;i++) { for (int x = 0,random = 0;x<listlength;x++) { if (thelist[x]!=list[i]) random++; if (random == listlength) { thelist[y] = list[i]; y++; } } } int z = 0; for (;;) { right = 0; eight = 0; cout << "guess the number ("<<z+1<<"times)---"; cin >> my; for (int a = 0; a < listlength;a++) { int k = 1; for(int m = a;m>=0;m--) { k*=10; } mylist [a]= my % k; mylist [a]/=(k/10); } int temp,tempi; int *p=mylist; for(tempi=0;tempi<listlength/2;tempi++) { temp=p[tempi]; p[tempi]=p[listlength-1-tempi]; p[listlength-1-tempi]=temp; } for (int g = 0; g < listlength;g++) { for (int j = 0; j < listlength;j++) { if (mylist[g] == thelist[j]) { if (g == j) { right++; } else { eight++; } } } } if (right == listlength) { cout << "You are right !!!" << endl; break; } else { cout << right << "." << " " << eight << "o" << endl; } z++; } } return EXIT_SUCCESS; }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值