Programaçao C++
Trabalho Universitário: Programaçao C++. Pesquise 862.000+ trabalhos acadêmicosPor: magnorafael • 13/10/2013 • 844 Palavras (4 Páginas) • 228 Visualizações
#include <iostream>
using namespace std;
int main (int argc, char *argv[])
{
char quit;
quit = '\0';
while (quit != 'q')
{
cout << "Hello ! This is a console app." << endl;
cout << "To create a console, go to Project Options and select" << endl;
cout << "\'Win32 Console\'." << endl;
cout << "Press q to quit " << endl;
cin >> quit;
}
return 0;
}
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
void Start ();
void GetResults ();
int i, j, life, maxrand;
char c;
void
Start ()
{
i = 0;
j = 0;
life = 0;
maxrand = 6;
cout << "Select difficulty mode:\n"; // the user has to select a difficutly level
cout << "1 : Easy (0-15)\n";
cout << "2 : Medium (0-30)\n";
cout << "3 : Difficult (0-50)\n";
cout << "or type another key to quit\n";
c = 30;
cin >> c; // read the user's choice
cout << "\n";
switch (c)
{
case '1' : maxrand = 15; // the random number will be between 0 and maxrand
break;
case '2' : maxrand = 30;
break;
case '3' : maxrand = 50;
break;
default : exit(0);
break;
}
life = 5; // number of lifes of the player
srand( (unsigned)time( NULL ) ); // init Rand() function
j = rand() % maxrand; // j get a random value between 0 and maxrand
GetResults();
}
void
GetResults ()
{
if (life <= 0)
// if player has no more life then he lose
{
cout << "You lose !\n\n";
...