这是家庭作业..我需要帮助c ++ 2008 [英] This is homework.. And i need help c++ 2008

查看:80
本文介绍了这是家庭作业..我需要帮助c ++ 2008的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在遵守所有规则的情况下为至少一个播放器制作Yahtzee程序.

每回合3次掷骰,使用5个骰子,玩家选择要握住和/或翻滚的骰子.并在计分卡上显示分数
这将是一个控制台应用程序.
我有此复制的代码,但无法正常工作.就我个人而言,我希望更容易处理.有人可以帮忙吗?
这是我到目前为止发现的东西,似乎似乎无法将它们合并在一起以使其正常工作.

I am to make a Yahtzee program for at least one playe rwith all rules apllied.

3 rolls per turn ,five dice used and player choice of what dice to hold and/ or r-roll. And a display of scores on a scorecard
this is to be a console application.
I have this copied code but it wont work. Personally I would like something easier to deal with. Can anyone help?
here is what I found so far just can''t seem to merge them together to make it work.

#include <iostream>
 #include <cstdlib>
 #include <time.h>
 using namespace std;
    int main() 
 {    
srand(static_cast<unsigned int="">(time (0)));   // Seeds the random number I would like to have a random roll on the five dice
int RandomValue =rand() %6;	
  int nums[5]; int i, j, input; int count[6]; 

 int sum = 0;  

         int num = 5;  

         int roll[5] = {0};  

         int count[6] = {0};  

         int score[13] = {0};  
                

                              
         cout<<"Please enter 5 numbers"<<endl;     // I Would like to put in a random 5 dice roll here         srand(static_cast<unsigned int="">(time (0))); 
 
                 for (int i=0; i<5; i++)  

                         cin>>roll[i];  

                            

                 for (int i=0; i<5; i++)  

                         sum += roll[i];    
                 

                switch(roll[5])  

                {  
                        case 1: ++count[0]; break;  
                         case 2: ++count[1]; break;  

                         case 3: ++count[2]; break;  

                         case 4: ++count[3]; break;  

                        case 5: ++count[4]; break;  

                        case 6: ++count[5]; break;  

 }  

         /*for (int i = 0; i < num;  // These following algorithms are incorrect is there an easier way?

         i++)  

                    

         {              if (roll[i] == 1)     

                         count[0]++;  
                        

                         if (roll[i] == 2)  

                        count[1]++;  

    count[2]++;  

                    

                         if (roll[i] == 4)  

                         count[3]++;  

                   

                        if (roll[i] == 5)  

                         count[4]++;  


                         if (roll[i] == 6)  
                        count[5]++;  

         }  
              */ 

                score[0] = count[0]*1;  

                score[1] = count[1]*2;  

                score[2] = count[2]*3;  

                score[3] = count[3]*4;  

                score[4] = count[4]*5;  

                score[5] = count[5]*6;  

           

               for (int i = 0; i <5; i++)  

         {              if (count[i]/3 >= 1)  

                        score[6] = sum;  

        }  

                 for (int i = 0; i <5; i++)  

        {              if (count[i]/4 >= 1)  

                        score[7] = sum;    

         }  

                 for (int i = 0; i <5; i++)  

        {              if (count[i]/3 >=1 && count[i]/2 >=1)  

                         score[8] = 25;  

         }                

                 for (int i = 0; i <5; i++)  

         {  

                 if ((count[0]*count[1]*count[2]*count[3]) == 1 ||  

                        (count[1]*count[2]*count[3]*count[4]) == 1 ||  

                         (count[2]*count[3]*count[4]*count[5]) == 1)  

                         score[9] = 30;  

        }  

         {      if ((count[0]*count[1]*count[2]*count[3]*count[4]) == 1 ||  

                        (count[1]*count[2]*count[3]*count[4]*count[5]) == 1)  

                         score[10] = 40;  

         }  

                 for (int i = 0; i < 5; i++)  

         {              if (count[i]/5 >= 1)  

                        score[11] = 50;  

       }  

                 score[12] = sum;  

                           

         cout<<setw(30)<<"******************************"<<endl;  

         cout<<"Ace's"<<setw(14)<<score[0]<<endl;  

         cout<<"Two's"<<setw(14)<<score[1]<<endl;  

         cout<<"Three's"<<setw(12)<<score[2]<<endl;  

         cout<<"Four's"<<setw(13)<<score[3]<<endl;  

         cout<<"Five's"<<setw(13)<<score[4]<<endl;  

         cout<<"Six's"<<setw(14)<<score[5]<<endl;  

         cout<<"Three of a Kind"<<setw(4)<<score[6]<<endl;  

         cout<<"Four of a Kind"<<setw(5)<<score[7]<<endl;  

         cout<<"Full House"<<setw(9)<<score[8]<<endl;  

         cout<<"Small Straight"<<setw(5)<<score[9]<<endl;  

         cout<<"Large Straight"<<setw(5)<<score[10]<<endl;  

         cout<<"YAHTZEE"<<setw(12)<<score[11]<<endl;  

         cout<<"Chance"<<setw(13)<<score[12]<<endl;  

         cout<<setw(30)<<"******************************"<<endl;  
           

        
} 
      
          for(j= 0; j < 14; j++) 
         
          for(i = 0; i < 5; i++) 
    {        
 nums[i] = rand()37;6 + 1;					// sets number of rolls to 37
 {
         cout << nums[i] << endl;
         switch(nums[i]);
        {        
             case 1: ++count[0]; break;
             case 2: ++count[1]; break;
             case 3: ++count[2]; break; 
             case 4: ++count[3]; break;  
             case 5: ++count[4]; break;
             case 6: ++count[5]; break;
             default: cout << "An error has occured!"; break;    // screen print if error occurs
        } 
        cout << "Choose which numbers you want to keep?( -1 to keep all numbers ) \n";   // user input which die to hold 
                 "\n";     
      cin >> input;
 }
           if(input == -1) 
         break;    
           if (input > 6		  
	 cout << "Please select number from 1 to 6 only \n\n";     
}           
  if()
 system("PAUSE");          
 return 0;  
}

推荐答案

我只能看到一个问题:代码是由非程序员编写的..

不,不,请不要生气:我不会劝阻您,并建议您这样做.恰恰相反:我想鼓励您成为一名程序员.这是您需要的第一件事,但是这将需要您极大地改变您的想法.

抱歉,但是我不能帮助您解决您要解决的问题并在截止日期之前完成.请记住,最后期限是您的问题,而不是我们的问题. 您没有提出自己的问题;这是非程序员的另一个征兆.您需要先更改自己,直到为时已晚.

让我们看看:

I can see only one problem: the code is written by a non-programmer.

No, no, please don''t get offended: I''m not going to discourage you and suggest to quite. Just the opposite: I want to encourage you to become a programmer. This is first thing you need, but it will require you to change your thinking dramatically.

Sorry, but I cannot help you to solve the problem you want to solve and meet deadline. Remember that a deadline is your problem, not ours. And you did not formulate your problem; and this is another sign of a non-programmer. You need to change yourself first until it''s too late.

Let''s see:

switch(roll[5])   
{  
   case 1: ++count[0]; break;  
   case 2: ++count[1]; break;   
   case 3: ++count[2]; break;   
   case 4: ++count[3]; break;  
   case 5: ++count[4]; break;   
   case 6: ++count[5]; break;  
}



程序员永远都不会写这样的东西,甚至连roll[5]都不会,因为不支持立即常量 5.类似于



A programmer will never write anything like that, not even roll[5], because immediate constant 5 is not supportable. It will be something like

++count[roll[maxRollNumber] - 1];



关于



Same thing about

score[0] = count[0]*1;  
score[1] = count[1]*2;
//...
// how many times do you have to write this line to start thinking instead?



必须为



Must be something like

for (int index = 0; index < maxRollNumber; ++index)
    score[index] *= 2;

等……您所写的内容与编程的想法完全相反.而且,甚至不要玩弄您需要首先通过测试并获得有效程序,修正问题的想法.在某些原则上,以后没有修复.从不.

并且,请在决定答复之前发出一个警告:请不要重复常见的错误,也不要说我是初学者".只是不要.我们知道,那又如何呢?这是完全不相关的.

And so on… What you have written is something opposite to the very idea of programming. And don''t even play with the idea that you need to pass the test first and get a working program, fix things letter. In certain principle things, there is no later fix. Never.

And, please, one warning before you decide to reply: please, don''t repeat a common mistake, don''t say "I''m a beginner". Just don''t. We know, so what? This is completely irrelevant.

Yoda 所写:

取消了解您所学.

—SA


这篇关于这是家庭作业..我需要帮助c ++ 2008的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆