Update
This commit is contained in:
parent
40befe907e
commit
6f5487312f
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"iostream": "cpp"
|
||||||
|
}
|
||||||
|
}
|
BIN
NumberGuessingGame
Executable file
BIN
NumberGuessingGame
Executable file
Binary file not shown.
60
NumberGuessingGame.cpp
Normal file
60
NumberGuessingGame.cpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <ctime>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
string italianNumber(int num) {
|
||||||
|
string units[] = {"", "uno", "due", "tre", "quattro", "cinque", "sei", "sette", "otto", "nove"};
|
||||||
|
string teens[] = {"dieci", "undici", "dodici", "tredici", "quattordici", "quindici", "sedici", "diciassette", "diciotto", "diciannove"};
|
||||||
|
string tens[] = {"", "", "venti", "trenta", "quaranta", "cinquanta", "sessanta", "settanta", "ottanta", "novanta"};
|
||||||
|
string hundreds[] = {"", "cento", "duecento", "trecento", "quattrocento", "cinquecento", "seicento", "settecento", "ottocento", "novecento"};
|
||||||
|
|
||||||
|
if (num < 10) return units[num];
|
||||||
|
else if (num < 20) return teens[num - 10];
|
||||||
|
else if (num < 100) {
|
||||||
|
string res = tens[num / 10];
|
||||||
|
if (num % 10 == 1 || num % 10 == 8) res.pop_back(); // Drop the last vowel for "uno" or "otto"
|
||||||
|
return res + units[num % 10];
|
||||||
|
} else if (num < 1000) {
|
||||||
|
string res = hundreds[num / 100];
|
||||||
|
int remainder = num % 100;
|
||||||
|
if (remainder > 0) res += italianNumber(remainder);
|
||||||
|
return res;
|
||||||
|
} else {
|
||||||
|
return "Numero troppo grande! (Number too large!)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
srand(time(0)); // Seed for random number generator
|
||||||
|
int num = rand() % 1000; // Generates a random number between 0 and 999
|
||||||
|
int choice;
|
||||||
|
|
||||||
|
cout << "The generated number is: " << num << ".\n";
|
||||||
|
cout << "1. English (Coming soon!)\n2. Italian\nChoose the language you want to write the number in: ";
|
||||||
|
cin >> choice;
|
||||||
|
|
||||||
|
if (choice == 1) {
|
||||||
|
cout << "Sorry, but English translation is currently unavailable right now. Please choose Italian.\n";
|
||||||
|
return 0;
|
||||||
|
} else if (choice == 2) {
|
||||||
|
string italian_num = italianNumber(num);
|
||||||
|
cout << "The number in Italian is: " << italian_num << "\n";
|
||||||
|
|
||||||
|
// Ask user for their guess
|
||||||
|
string guess;
|
||||||
|
cout << "Guess the written equivalent of the number: ";
|
||||||
|
cin.ignore(); // Clear input buffer
|
||||||
|
getline(cin, guess); // Read full line for multi-word guesses
|
||||||
|
|
||||||
|
if (italian_num == guess) {
|
||||||
|
cout << "Hai indovinato correttamente! (You guessed correctly!)\n";
|
||||||
|
} else {
|
||||||
|
cout << "Risposta sbagliata. Riprova la prossima volta! (Wrong guess, try again next time!)\n";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cout << "Scelta non valida. (Invalid choice)\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user