I think i'm after this c+p program
#include <iostream>
using namespace std;
int main() {
int a;
int b;
cout << "Please enter a interger: " << endl;
cin >> a;
cout << "Please enter another interger: " << endl;
cin >> b;
cout << "The total of both numbers is: " << a + b << endl;
return 0;
}
Click Here to visit the official MPGH wiki! Keep up with the latest news and information on games and MPGH! To check out pages dedicated to games, see the links below!
dd/mm/yyyy
Member - 31/01/2015
Premium - 12/09/2016
Call of Duty minion - 05/11/2016 - 05/11/2019
BattleOn minion - 28/02/2017 - 05/11/2019
Battlefield minion - 30/05/2017 - 05/11/2019
Other Semi-Popular First Person Shooter Hacks minion - 21/09/2017 - 17/09/2019
Publicist - 07/11/2017 - 02/08/2018
Cock Sucker - 01/12/2017 - Unknown
Minion+ - 06/03/2018 - 05/11/2019
Fortnite minion - 08/05/2018 - 05/11/2019
Head Publicist - 08/10/2018 - 10/01/2020
Developer Team - 26/10/2019 - 10/01/2020
Former Staff - 10/01/2020
Doge30 (05-17-2017)
Click Here to visit the official MPGH wiki! Keep up with the latest news and information on games and MPGH! To check out pages dedicated to games, see the links below!
dd/mm/yyyy
Member - 31/01/2015
Premium - 12/09/2016
Call of Duty minion - 05/11/2016 - 05/11/2019
BattleOn minion - 28/02/2017 - 05/11/2019
Battlefield minion - 30/05/2017 - 05/11/2019
Other Semi-Popular First Person Shooter Hacks minion - 21/09/2017 - 17/09/2019
Publicist - 07/11/2017 - 02/08/2018
Cock Sucker - 01/12/2017 - Unknown
Minion+ - 06/03/2018 - 05/11/2019
Fortnite minion - 08/05/2018 - 05/11/2019
Head Publicist - 08/10/2018 - 10/01/2020
Developer Team - 26/10/2019 - 10/01/2020
Former Staff - 10/01/2020
Hitokiri~ (05-10-2017)
Well the code you wrote is really simple lmao..
Here you have code of random number game I created 3 years ago!
Code:
#include <iostream>
#include <cmath>
#include <string>
#include <windows.h>
#include <ctime>
using namespace std;
int main()
{
int num, randnum;
char yn;
string name;
srand(time(NULL));
cout << "Welcome to random number game! Please enter your name! :"; cin >> name;
cout << "Hello " << name << " so do you really want to play? If yes than enter 'y', and if no then enter 'n'!: "; cin >> yn;
if (yn == 'n' || yn == 'N')
{
cout << "Well bye then! Come later please!" << endl;
}
while (true)
{
cout << "Ok so you want to play.. The computer will imagine random number and you have to guess what number it is!" << endl;
cin >> num;
randnum = rand() % 10;
if (randnum == num)
cout << "Well done! You won the game!";
else
cout << "Well you lost the game! Try again! The number computer imagined was: " << randnum << endl;
}
system("pause");
return 0;
}
Last edited by V3n0mCZE; 05-11-2017 at 11:23 AM.
This is simple too.
A little more complex, but simple.
Here is a simple game I made with a friend for class(use the numpad to control the character):
// Library
#include <ctime>
#include <iostream>
// Platform
#include <conio.h>
#include <Windows.h>
using std::cout;
using std::endl;
typedef unsigned int uint;
typedef int Health;
typedef int Coord;
typedef int Tile;
typedef char Sprite;
#define FORALL(m) for(int ndx=0;ndx < int(m);ndx++)
// ----------------------------------------------
// Random numbers
void randomInit()
{
srand(static_cast<uint>(time(NULL)));
}
int randomTo(int n)
{
return rand() % n;
}
int randomBetween(int begin, int end)
{
int diff = (end - begin) + 1;
return begin + (rand() % diff);
}
// ----------------------------------------------
// Console Graphics
#define kRed FOREGROUND_RED|FOREGROUND_INTENSITY
#define kBlue FOREGROUND_BLUE|FOREGROUND_INTENSITY
#define kGreen FOREGROUND_GREEN|FOREGROUND_INTENSITY
#define kYellow FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSI TY
#define kWhite FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|FO REGROUND_INTENSITY
void Console_clear()
{
// system("CLS");
HANDLE instance = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(instance, &info);
COORD pos = { 0, 0};
uint size = info.dwSize.X * info.dwSize.Y;
DWORD written;
FillConsoleOutputCharacter(instance, ' ', size, pos, &written);
}
void Console_printAt(int x, int y, int color, char c)
{
COORD coord = {x,y};
HANDLE instance = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(instance, coord);
SetConsoleTextAttribute(instance, color);
cout << c;
}
int main()
{
// Setup/Init - Install -----------------------
randomInit();
// Playspace
const Tile kEdge_left = 0,
kEdge_top = 0,
kEdge_right = 79,
kEdge_bottom = 23;
// NPCs - the horde of enemies
const Sprite kEnemySprite = '$';
const Health kFullyAlive = 100,
kWounded = 50,
kMortallyWounded = 0,
kDead = -1;
const Tile kMoveMin = 1,
kMoveMax = 3,
kMoveOpposite = -1;
const uint kEnemyCount = 15;
int enemiesAlive = kEnemyCount;
Health enemyLife[kEnemyCount];
Coord enemyX[kEnemyCount], enemyY[kEnemyCount]; // coords
int enemyVelX[kEnemyCount], enemyVelY[kEnemyCount]; // velocity
for (int ndx = 0; ndx < kEnemyCount; ndx++) {
enemyLife[ndx] = kFullyAlive;
enemyX[ndx] = randomBetween(kEdge_left, kEdge_right);
enemyY[ndx] = randomBetween(kEdge_top, kEdge_bottom);
enemyVelX[ndx] = randomBetween(kMoveMin, kMoveMax);
enemyVelY[ndx] = randomBetween(kMoveMin, kMoveMax);
}
// Boss - enemy boss
const Sprite kBossSprite = 'M';
const Health kBossFullyAlive = 150,
kBossWounded1 = 100,
kBossWounded2 = 50;
Health bossLife = kBossFullyAlive;
Coord bossX = randomBetween(kEdge_left, kEdge_right),
bossY = randomBetween(kEdge_top, kEdge_bottom);
// Player - our hero!
const Sprite kPlayerSprite = '0';
const Health kPlayerFullyAlive = 50;
Health playerLife = kPlayerFullyAlive;
Coord playerX = (kEdge_right - kEdge_left)/2, // center player
playerY = (kEdge_bottom - kEdge_top)/2;
// Game Loop -----------------------
bool playing = true;
do {
// one frame of the game
// Inputs
if (_kbhit() > 0) {
char key = tolower(_getch());
if (key == 'q') playing = false;
//Key Handler
int dist = 1;
int dx = 0;
int dy = 0;
if (key == '8') dy = -dist; //up
else if (key == '2') dy += dist; //down
else if (key == '4') dx -= dist; //left
else if (key == '6') dx += dist; //right
else if (key == '1') dx -= dist, dy += dist; //down-left
else if (key == '3') dx += dist, dy += dist; //down-right
else if (key == '7') dx -= dist, dy -= dist; //up-left
else if (key == '9') dx += dist, dy -= dist; //up-right
playerX += dx;
playerY += dy;
}
//Border Control
// check borders and teleport to opposite side
if (playerY > kEdge_bottom) playerY = kEdge_top;
if (playerY < kEdge_top) playerY = kEdge_bottom;
if (playerX > kEdge_right) playerX = kEdge_left;
if (playerX < kEdge_left) playerX = kEdge_right;
// NPC Tasks - characters
FORALL(kEnemyCount){
if (enemyLife[ndx] == kDead) continue;
enemyX[ndx] += enemyVelX[ndx];
enemyY[ndx] += enemyVelY[ndx];
if (enemyX[ndx] < kEdge_left){
enemyX[ndx] = kEdge_left;
enemyVelX[ndx] *= kMoveOpposite;
}
if (enemyX[ndx] > kEdge_right){
enemyX[ndx] = kEdge_right;
enemyVelX[ndx] *= kMoveOpposite;
}
if (enemyY[ndx] < kEdge_top){
enemyY[ndx] = kEdge_top;
enemyVelY[ndx] *= kMoveOpposite;
}
if (enemyY[ndx] > kEdge_bottom){
enemyY[ndx] = kEdge_bottom;
enemyVelY[ndx] *= kMoveOpposite;
}
}
FORALL(randomBetween(5,15)){
if (bossX < kEdge_left){
bossX = kEdge_left;
}
if (bossX > kEdge_right){
bossX = kEdge_right;
}
if (bossY < kEdge_top){
bossY = kEdge_top;
}
if (bossY > kEdge_bottom){
bossY = kEdge_bottom;
}
int distB = 1;
int dXB = 0,
dYB = 0;
dXB = randomBetween(-1,1);
dYB = randomBetween(-1,1);
bossX += dXB; bossY += dYB;
}
// Collision testing
// Rendering
Console_clear();
Console_printAt(playerX, playerY, kWhite, kPlayerSprite );
Console_printAt(bossX, bossY, kRed, kBossSprite);
// Add for-loop to render list of enemies
FORALL(kEnemyCount) {
Console_printAt(enemyX[ndx], enemyY[ndx], kGreen, kEnemySprite);
}
Sleep(100);
} while (playing);
// Clean-up/De-install -----------------------
return EXIT_SUCCESS;
}
Do you people not remember there is a code tag?
Code:#include <ctime> #include <iostream> // Platform #include <conio.h> #include <Windows.h> using std::cout; using std::endl; typedef unsigned int uint; typedef int Health; typedef int Coord; typedef int Tile; typedef char Sprite; #define FORALL(m) for (int ndx = 0; ndx < int(m); ndx++) // ---------------------------------------------- // Random numbers void randomInit() { srand(static_cast<uint>(time(NULL))); } int randomTo(int n) { return rand() % n; } int randomBetween(int begin, int end) { int diff = (end - begin) + 1; return begin + (rand() % diff); } // ---------------------------------------------- // Console Graphics #define kRed FOREGROUND_RED | FOREGROUND_INTENSITY #define kBlue FOREGROUND_BLUE | FOREGROUND_INTENSITY #define kGreen FOREGROUND_GREEN | FOREGROUND_INTENSITY #define kYellow FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSI TY #define kWhite FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FO REGROUND_INTENSITY void Console_clear() { // system("CLS"); HANDLE instance = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO info; GetConsoleScreenBufferInfo(instance, &info); COORD pos = { 0, 0 }; uint size = info.dwSize.X * info.dwSize.Y; DWORD written; FillConsoleOutputCharacter(instance, ' ', size, pos, &written); } void Console_printAt(int x, int y, int color, char c) { COORD coord = { x, y }; HANDLE instance = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(instance, coord); SetConsoleTextAttribute(instance, color); cout << c; } int main() { // Setup/Init - Install ----------------------- randomInit(); // Playspace const Tile kEdge_left = 0, kEdge_top = 0, kEdge_right = 79, kEdge_bottom = 23; // NPCs - the horde of enemies const Sprite kEnemySprite = '$'; const Health kFullyAlive = 100, kWounded = 50, kMortallyWounded = 0, kDead = -1; const Tile kMoveMin = 1, kMoveMax = 3, kMoveOpposite = -1; const uint kEnemyCount = 15; int enemiesAlive = kEnemyCount; Health enemyLife[kEnemyCount]; Coord enemyX[kEnemyCount], enemyY[kEnemyCount]; // coords int enemyVelX[kEnemyCount], enemyVelY[kEnemyCount]; // velocity for (int ndx = 0; ndx < kEnemyCount; ndx++) { enemyLife[ndx] = kFullyAlive; enemyX[ndx] = randomBetween(kEdge_left, kEdge_right); enemyY[ndx] = randomBetween(kEdge_top, kEdge_bottom); enemyVelX[ndx] = randomBetween(kMoveMin, kMoveMax); enemyVelY[ndx] = randomBetween(kMoveMin, kMoveMax); } // Boss - enemy boss const Sprite kBossSprite = 'M'; const Health kBossFullyAlive = 150, kBossWounded1 = 100, kBossWounded2 = 50; Health bossLife = kBossFullyAlive; Coord bossX = randomBetween(kEdge_left, kEdge_right), bossY = randomBetween(kEdge_top, kEdge_bottom); // Player - our hero! const Sprite kPlayerSprite = '0'; const Health kPlayerFullyAlive = 50; Health playerLife = kPlayerFullyAlive; Coord playerX = (kEdge_right - kEdge_left) / 2, // center player playerY = (kEdge_bottom - kEdge_top) / 2; // Game Loop ----------------------- bool playing = true; do { // one frame of the game // Inputs if (_kbhit() > 0) { char key = tolower(_getch()); if (key == 'q') playing = false; //Key Handler int dist = 1; int dx = 0; int dy = 0; if (key == '8') dy = -dist; //up else if (key == '2') dy += dist; //down else if (key == '4') dx -= dist; //left else if (key == '6') dx += dist; //right else if (key == '1') dx -= dist, dy += dist; //down-left else if (key == '3') dx += dist, dy += dist; //down-right else if (key == '7') dx -= dist, dy -= dist; //up-left else if (key == '9') dx += dist, dy -= dist; //up-right playerX += dx; playerY += dy; } //Border Control // check borders and teleport to opposite side if (playerY > kEdge_bottom) playerY = kEdge_top; if (playerY < kEdge_top) playerY = kEdge_bottom; if (playerX > kEdge_right) playerX = kEdge_left; if (playerX < kEdge_left) playerX = kEdge_right; // NPC Tasks - characters FORALL(kEnemyCount) { if (enemyLife[ndx] == kDead) continue; enemyX[ndx] += enemyVelX[ndx]; enemyY[ndx] += enemyVelY[ndx]; if (enemyX[ndx] < kEdge_left) { enemyX[ndx] = kEdge_left; enemyVelX[ndx] *= kMoveOpposite; } if (enemyX[ndx] > kEdge_right) { enemyX[ndx] = kEdge_right; enemyVelX[ndx] *= kMoveOpposite; } if (enemyY[ndx] < kEdge_top) { enemyY[ndx] = kEdge_top; enemyVelY[ndx] *= kMoveOpposite; } if (enemyY[ndx] > kEdge_bottom) { enemyY[ndx] = kEdge_bottom; enemyVelY[ndx] *= kMoveOpposite; } } FORALL(randomBetween(5, 15)) { if (bossX < kEdge_left) { bossX = kEdge_left; } if (bossX > kEdge_right) { bossX = kEdge_right; } if (bossY < kEdge_top) { bossY = kEdge_top; } if (bossY > kEdge_bottom) { bossY = kEdge_bottom; } int distB = 1; int dXB = 0, dYB = 0; dXB = randomBetween(-1, 1); dYB = randomBetween(-1, 1); bossX += dXB; bossY += dYB; } // Collision testing // Rendering Console_clear(); Console_printAt(playerX, playerY, kWhite, kPlayerSprite); Console_printAt(bossX, bossY, kRed, kBossSprite); // Add for-loop to render list of enemies FORALL(kEnemyCount) { Console_printAt(enemyX[ndx], enemyY[ndx], kGreen, kEnemySprite); } Sleep(100); } while (playing); // Clean-up/De-install ----------------------- return EXIT_SUCCESS; }
vidsac (07-17-2017)
Click Here to visit the official MPGH wiki! Keep up with the latest news and information on games and MPGH! To check out pages dedicated to games, see the links below!
dd/mm/yyyy
Member - 31/01/2015
Premium - 12/09/2016
Call of Duty minion - 05/11/2016 - 05/11/2019
BattleOn minion - 28/02/2017 - 05/11/2019
Battlefield minion - 30/05/2017 - 05/11/2019
Other Semi-Popular First Person Shooter Hacks minion - 21/09/2017 - 17/09/2019
Publicist - 07/11/2017 - 02/08/2018
Cock Sucker - 01/12/2017 - Unknown
Minion+ - 06/03/2018 - 05/11/2019
Fortnite minion - 08/05/2018 - 05/11/2019
Head Publicist - 08/10/2018 - 10/01/2020
Developer Team - 26/10/2019 - 10/01/2020
Former Staff - 10/01/2020
You're the best programmers I ever saw, but some tips. You can use 'int a, b; ' and not use an useless space. Also, you should try some array problems.
There's a bug in your code. The 'while (true)' will still run even if the user chooses not to play. If you want to terminate the program when the user says "No" then you should add "return 0;" under the if statement, so you need it to be like this:
if (yn == 'n' || yn == 'N')
{
cout << "Well bye then! Come later please!" << endl;
return 0; // I added this
}
I like my code:
Code:using namespace std; void main() { }