1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <ctime>
using namespace std;
void function();
void function()
{
// Declaring a string object
int hitPoints=10;
int strike;
string strl1 = ("#include <iostream>");
string strl2 = ("using namespace std;");
string strl3 = ("int main()");
string strl4 = ("{");
string strl5 = ("cout << fireStrike;");
string strl6 = ("return 0;");
string strl7 = ("}");
string str1;
string str2;
string str3;
string str4;
string str5;
string str6;
string str7;
cout << "Write a c++ Program to cast a fire strike \n";
while (hitPoints != 0)
{
while(strl1 != str1)
{
getline(cin, str1);
if(strl1 != str1)
cout << "That is not correct, try again \n";
}
while(strl2 != str2)
{
getline(cin, str2);
if(strl2 != str2)
cout << "That is not correct, try again \n";
}
while(strl3 != str3)
{
getline(cin, str3);
if(strl3 != str3)
cout << "That is not correct, try again \n";
}
while(strl4 != str4)
{
getline(cin, str4);
if(strl4 != str4)
cout << "That is not correct, try again \n";
}
while(strl5 != str5)
{
getline(cin, str5);
if(strl5 != str5)
cout << "That is not correct, try again \n";
}
while(strl6 != str6)
{
getline(cin, str6);
if(strl6 != str6)
cout << "That is not correct, try again \n";
}
while(strl7 != str7)
{
getline(cin, str7);
if(strl7 != str7)
cout << "That is not correct, try again \n";
}
{
srand((unsigned)time(0));
strike = rand() % 10 + 1;
cout << "You have cast a fireStrike at the monster \n";
cout << "you hit a " << strike;
hitPoints = hitPoints - strike;
if (hitPoints <= 0)
hitPoints = 0;
cout << "The monster now has " << hitPoints << " left \n";
str1.clear();
str2.clear();
str3.clear();
str4.clear();
str5.clear();
str6.clear();
str7.clear();
}
}
cout << "You have killed a monster! \n";
}
int main()
{
function();
return 0;
}
Put the code you need help with here.
|