【解決方法】以下のCプログラムをphpに変換


C++
main()
{
char c;
printf("enter y for yes and n for no \n");
scanf("%c",&c);
if(c=='y')
 {
execute some statements

}
else
{
some statements
}
}

解決策 4

Unsigned char Checksum (const char *s,int nLength)
{
Unsigned char result;
result=0;
for(int i=0;i<Length;i++)
{
result ^=*s++
}
return result;
}

解決策 2

JSプロンプトでユーザーから入力を取得し、PHPで次のようなことを行う必要があります

echo(“はいの場合は Y、いいえの場合は N を入力してください”)

if(//ここにプロンプ​​ト値 == “Y”)
//声明
それ以外

//声明

解決策 1

PHPには、ユーザー入力を入力するためのコンソールがなく、サーバー側のWebページでのみ機能します

解決策 3

コンソールでphpを実行したい場合は、phpのバージョン4から今日まで(私のバージョンは7.2です)、readlineで機能する簡単な解決策があります。
残念ながら、ユーザーは入力後にエンターを押す必要があります

PHP
$c = readline("Enter y for yes and n for no and press enter to confirm\n");
$c = strtolower($c);
if ($c == 'y' || $c == 'yes' ) {
    echo 'You chose yes' . PHP_EOL;
} else {
    echo 'You chose no [' . $c . ']' . PHP_EOL;
}
echo 'exiting program...' . PHP_EOL;

stream_get_line 関数を使用することもできます

コメント

タイトルとURLをコピーしました