Results 1 to 8 of 8
Thread: C++
Hybrid View
-
13th September 2008 03:05 #1
C++
. : - , . , 3 . 2 , : . : 2 1 - . , : . : 0 , : ! . , . DO-WHILE loop IF statement, , , . . :
#include <cstdlib>
#include <iostream>
using namespace std;
int main() {
// Variables
int randnum, usernum, chancenum = 2;
// Random Number Generator
srand(time(0));
randnum = rand()% 10 + 1;
// Welcoming Text
cout << "The random number is:" << randnum << endl;
cout <<"Welcome to the Number Guessing Game!!\n";
cout <<"************************************* \n\n";
cout <<"Try to guess the number that has been generated.\n";
cout <<"Please enter a number between 1 and 10 (including 1 and 10): ";
// Begining of a DO - WHILE Loop
do {
cin >> usernum;
if (randnum == usernum)
cout << "That is correct, you win!\n\nThank you for playing the Number Guessing Game!\n\n\n";
else {
cout << "Sorry, this is incorrect. You have " << chancenum << " more chances left";
chancenum--;
}
} while (chancenum >= 0 && randnum != usernum);
// Execution Definitions
system("PAUSE");
return EXIT_SUCCESS;
}|Asus P5K Premium WiFi|Intel C2D E6750|Kingston 2x1GB@667MHz|Seagate 250GB+500GB|Coolmax CP 500W|Asus EN 8800 GTS 320MB|
-
13th September 2008 13:32 #2Code:
#include <cstdlib> #include <iostream> using namespace std; int main() { // Variables int randnum, usernum, chancenum = 2; // Random Number Generator srand(time(0)); randnum = rand()% 10 + 1; // Welcoming Text cout << "The random number is:" << randnum << endl; cout <<"Welcome to the Number Guessing Game!!\n"; cout <<"************************************* \n\n"; cout <<"Try to guess the number that has been generated.\n"; cout <<"Please enter a number between 1 and 10 (including 1 and 10): "; // Begining of a DO - WHILE Loop do { cin >> usernum; if (randnum == usernum) cout << "That is correct, you win!\n\nThank you for playing the Number Guessing Game!\n\n\n"; else if(chancenum == 0) cout<<"You Lose! :("<<"\n"; else { cout << "Sorry, this is incorrect. You have " << chancenum << " more chances left"; --chancenum; } } while (chancenum >= 0 && randnum != usernum); // Execution Definitions system("PAUSE"); return EXIT_SUCCESS; }Thou hast not to like it, thou hast just to do it.
-
14th September 2008 20:48 #3
. . , if, else, . ! !
|Asus P5K Premium WiFi|Intel C2D E6750|Kingston 2x1GB@667MHz|Seagate 250GB+500GB|Coolmax CP 500W|Asus EN 8800 GTS 320MB|
-
15th September 2008 15:53 #4
:
, , -. , Warning srand, unsigned int. , , , .Code:#include <cstdlib> #include <iostream> #include <time.h> using namespace std; int main() { // Variables int randnum, usernum, chancenum = 3; // Random Number Generator srand(time(0)); randnum = rand()% 10 + 1; // Welcoming Text cout << "The random number is:" << randnum << endl; cout <<"Welcome to the Number Guessing Game!!\n"; cout <<"************************************* \n\n"; cout <<"Try to guess the number that has been generated.\n"; // Begining of a DO - WHILE Loop do { cout <<"Please enter a number between 1 and 10 (including 1 and 10): "; cin >> usernum; if (randnum == usernum) cout << "That is correct, you win!\n\nThank you for playing the Number Guessing Game!\n\n\n"; else { if (--chancenum) cout << "Sorry, this is incorrect. You have " << chancenum << " more chances left\n"; } } while (chancenum > 0 && randnum != usernum); //End of DO-WHILE if (!chancenum) cout << "Incorrect, you lose\n\n"; // Execution Definitions system("PAUSE"); return EXIT_SUCCESS; }
Fujistu Lifebook E756 | Core i7-6500U / 400MHz-3.1GHz | 8 GB DDR4-2133 | Samsung PM871 / 256 GB SSD | 15" 1920x1080 | Manjaro Linux + kernel 4.19
-
4th November 2008 22:21 #5
. (, , ), , : "^" , float? Visual Studio 2008 .
: error C2296: '^' : illegal, left operand has type 'float'Code:#include "stdafx.h" #include "stdio.h" #include "math.h" int main() { float a, b, c, p, s,r ; printf("A e:"); scanf("%f", &a); printf("B e:"); scanf("%f", &b); printf("C e:"); scanf("%f", &c); p=(a+b+c)/2; r=a/2; s = sqrt(p*((p-c)*(p-c)*(p-a)))+ (a*b) + (3.14*(r^2)); printf("Powyrhninata e:", s); return 0; }
?MSI B550i Gaming Edge Wifi | Ryzen 9 5900X [Thermalright AXP-100C65 + Noctua A9x14] | G.Skill 2x16GB F4-3200C16Q-32GTZR | AMD RX 6800XT | EVO970 500GB + EVO850 250GB + EVO850 500GB + DS119j | Corsair SF750 Platinum | ASUS MG279Q | Razer DeathAdder V2 Pro | Keychron K6 Modded | SligerSM550
-
4th November 2008 22:53 #6
-
4th November 2008 23:17 #7
, - r*r; pow , .
EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|
-
4th November 2008 23:34 #8MSI B550i Gaming Edge Wifi | Ryzen 9 5900X [Thermalright AXP-100C65 + Noctua A9x14] | G.Skill 2x16GB F4-3200C16Q-32GTZR | AMD RX 6800XT | EVO970 500GB + EVO850 250GB + EVO850 500GB + DS119j | Corsair SF750 Platinum | ASUS MG279Q | Razer DeathAdder V2 Pro | Keychron K6 Modded | SligerSM550




Reply With Quote

Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in