SOGO論壇
  登入   註冊   找回密碼
查看: 987|回覆: 1
列印 上一主題 下一主題

[問題求助] 關於c++轉成c後有問題 [複製連結]

Rank: 4

狀態︰ 離線
跳轉到指定樓層
1
發表於 2011-4-18 21:39:11 |只看該作者 |倒序瀏覽
從網路下載一猜數字遊戲
因剛學c語言
所以想把它改寫後卻執行有問題
想請教大大那裡出錯
謝謝
原c++程式碼
#include <iostream>
#include <stdio.h>

using namespace std;  


int main( int argc, char *argv[] )
{
    printf( "\n HsK test! \n\n  猜數字遊戲 \n" );
     
    int byby = 5;
  srand((unsigned) time(NULL));  //剛更新 ^^   
   int min = 0, max = 100, round = 0, this_round = rand()%100+1;
    int player;
    std::string again;  
     
    while(byby == 5)
    {               
                cout << " Max=" << max << " ;  Min=" << min << " ;" << endl;
                cout << "  I Guess :";
                cin >> player;
                cout << endl;
                 
                if (player <= min || player >= max)
                {
                           cout << "注意!!!" << endl;
                           
                           if (player <= min)
                            player = min;
                           else if (player >= max)
                                player = max;
                }
                else
                {
                if (player == this_round)
                {
                           if (round == 0)
                           {
                                     cout << "真厲害!! 一次就猜中!" << endl;
                                     cout << "另起新局?  (Y/N)" << endl;
                                     cout << "   ------>";
                                     cin >> again;
                                      
                                     if(again=="Y"||again=="y")
                                     {
                                               min = 0;
                                               max = 100;
                                               round = 0;
                                               this_round = rand () % 100 + 1;
                                     }
                                     else
                                               break;
                           }
                           else
                           {                     
                                                printf( "\n..bingo..猜數字遊戲 %d次猜中 \n", round);   
                                                cout << "另起新局?  (Y/N)" << endl;   
                                                cout << "   ------>";
                                                cin >> again;
                                                
                                                if (again == "Y" || again == "y")
                                                {
                                                          min = 0;
                                                          max = 100;
                                                          round = 0;
                                                          this_round = rand () % 100 + 1;
                                                }
                                                else
                                                          break;
                           }
                }
                else
                {
                    if (player > this_round)
                    {
                               max = player;
                    }
                    else
                    {
                        min = player;
                    }
                    round += 1;
                }
                }
    }
     
    return 1;
}
                     
   
改寫成c後如下
請大大們幫小弟改正好嗎
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
int main( int argc, char *argv [] )

{
    char again;
    int byby = 5;
    srand((unsigned) time(NULL));  //剛更新 ^^   
    int min = 0, max = 99, round = 0, this_round = rand()%100+0;
    int player;      
    while(byby == 5)
    {           printf(" max=%d; min=%d;\n",max,min);     
                printf("I Guess :");
                scanf("%d",&player);
                printf("\n");
                 
                if (player <= min || player >= max)
                {
                           printf("注意!!!\n") ;
                           
                           if (player <= min)
                            player = min;
                           else if (player >= max)
                                player = max;
                }
                else
                {
                if (player == this_round)
                {
                           if (round == 0)
                           {
                                    printf("真厲害!! 一次就猜中!");
                                     printf("另起新局?  (Y/N)" );
                                     printf("   ------>");
                                     again=getche();
                                      
                                     if(again=='Y'||again=='y')
                                     {
                                               min = 0;
                                               max = 99;
                                               round = 0;
                                               this_round = rand () % 100 + 0;
                                     }
                                     else
                                               break;
                           }
                           else
                           {                     
                                                printf( "\n..bingo.. 猜數字遊戲 %d次猜中 \n", round);
                           
                                                
                                                printf("另起新局?  (Y/N)");   
                                                printf("   ------>");
                                                scanf("%c",&again);
                                                
                                                if (again == 'Y' || again == 'y')
                                                {
                                                          min = 0;
                                                          max = 99;
                                                          round = 0;
                                                          this_round = rand () % 100 + 0;
                                                }
                                                else
                                                       break;   
                           }
                }
                else
                {
                    if (player > this_round)
                    {
                               max = player;
                               printf("數目猜小一點\n");
                    }
                    else
                    {
                        min = player;
                        printf("數目猜大一點\n");
                    }
                    round += 1;
                }
                }
    }
   
     system("pause");
     return 0;
}

《 本帖最後由 csr 於 2011-4-18 22:07 編輯 》
喜歡嗎?分享這篇文章給親朋好友︰
               感謝作者     

Rank: 4

狀態︰ 離線
2
發表於 2011-5-8 20:09:36 |只看該作者
程式已自行解決
謝謝大家
請注意︰利用多帳號發表自問自答的業配文置入性行銷廣告者,將直接禁訪或刪除帳號及全部文章!
您需要登錄後才可以回覆 登入 | 註冊


本論壇為非營利自由討論平台,所有個人言論不代表本站立場。文章內容如有涉及侵權,請通知管理人員,將立即刪除相關文章資料。侵權申訴或移除要求:abuse@oursogo.com

GMT+8, 2024-5-5 22:30

© 2004-2024 SOGO論壇 OURSOGO.COM
回頂部