"int main()"のかっこ内に "random"を宣言する方法がわかりません。 (私はC++の初心者です)C++推測ゲームエラー
私のコードを見て、試してみてください。この問題を解決する方法を知っていると思うと答えてください。それは私にはたくさんのことを意味します。ありがとう!一方、私は自分自身でも問題を解決しようとしています。
注:具体的にするには、Code :: Blocksを使用しています。
エラーは、私のコードのLine 7/9にあります。
#include <iostream>
#include <stdlib.h>
#include <conio.h>
using namespace std;
int main()
{
int rn = random() % 21; // generates a random int from 0 to 20
// First output asking the user to guess the number
cout << "Please guess my number :" << endl;
int u;
cin >> u;
while (u != rn) // Calculates the answer that you give
{
// If the user's number is greater than the random number
// the program will let you know it's too large
if (u > rn)
{
cout << "You guessed too big!" << endl;
}
// On the other hand, if the user guesses to small
// the program will tell them that it's too small
else if (u < rn)
{
cout << "You guessed too small!" << endl;
}
// If the user does not get the right number, the program
// will tell the user to guess again
cout << "Please guess again :" << endl;
cin >> u;
}
// If the user guesses the number correctly, the program
// will say that they got it right, and end the program
cout << "You guessed it right!" << endl;
getch();
}
ここで更新され、コンパイラエラーです:
|| ===ビルド:推測でデバッグ番号(コンパイラ:GNU GCCコンパイラ)===ここ
は、以下の私の更新されたコードです|
C:\ Users \ Minecraftship \ Documents \ CPPプログラムブック\推測番号\ main.cpp || 関数 'int main()'で:| |
C:\ Users \ Minecraftship \ Documents \ CPPプログラムブック\推測番号\ main.cpp | 12 |
エラー: 'randomize'はこのスコープで宣言されていませんでした。
|| ===ビルドに失敗しました:1つのエラー(s)は、0警告(秒)(0分(秒)、0秒(秒))=== |問題は
は、あなたのコンパイラがエラーに並ぶ何を教えていますありますか?もしそうなら、その情報は参考になります。 –
6行目にはセミコロンがありません。int main(); – yussuf
'while(u = rn)'が疑わしいと思われる –