- Messages
- 6,990
- Location
- Toronto, Canada
Ah okay now you're getting into more advanced coding. Not too hard for your level though. Give me a few minutes and I'll post up an example of what you want.
#include <iostream>
using namespace std;
int main()
{
char answer[5];
while(strcmp("exit", answer))
{
cout << "Do you like sushi? Type yes or no (or exit to quit): ";
cin >> answer;
if(!strcmp("yes", answer))
{
cout << "\nWow, you like sushi!\n\n";
}
else if(!strcmp("no", answer))
{
cout << "\nGood, sushi's gross!\n\n";
}
else if(!strcmp("exit", answer))
{
cout << "\nExiting...\n\n";
}
else
{
cout << "\nWell if you can't even type yes or no..."
<< "\nhow do you expect me to trust your opinion?\n"
<< endl;
}
}
return 0;
}
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <cmath>
srand(time(NULL));
char answer[4];
int stat, strength, defence, choice2, pot1, pot2, pot3, pot4, outcome, test;
char choice;
cout << "\nStrength: ";
cin >> strength;
cout << "\nDefence: ";
cin >> defence;
cout << "You reach a road, do you want to turn left or right ?\n\n";
cout << "1, Left: Danger, 30percent. Stat Potential Increase, 30ppercent\n\n";
cout << "2, Right: Danger, 60percent. Stat Potential, 70percent \n\n";
cout << "Enter choice (1 or 2): ";
cin >> choice2;
cout << "\n";
switch(choice2) {
case 1:
pot1 = 5;
if(pot1 == 4)
{
cout << "You encounter no dangers, your stats remain the same\n\n";
}
else
{
cout << "-------Start of Battle------";
cout << "\n\n\n";
cout << "You encountered a Black Bear (Level 15)\n";
cout << "\nStrength is: " << strength << "...Defence is: " << defence;
stat = strength + defence;
cout << "\n\n";
cout << "Stats equal: " << stat;
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <cmath>
using namespace std;
int main()
{
srand(time(NULL));
char answer[4];
int stat, strength, defence, choice2, pot1, pot2, pot3, pot4, outcome, test;
char choice;
cout << "***Welcome to Mayple's Big Adventure***\n\n";
cout << "Lets start by setting your statistics: \n";
begin:
cout << "\nStrength: ";
cin >> strength;
cout << "\nDefence: ";
cin >> defence;
cout << "\nYour Strength is " << strength << " and your Defence is " << defence << "\n";
cout << "\nAre you happy with these stats? Yes or No: ";
choice = 'Yes' || 'No';
cin >> answer;
if(!strcmp("Yes", answer))
{
cout << "\n" << "Good, let us continue...\n\n";
goto start;
}
else
{
cout << "\n" << "Ok, lets try again...\n";
goto begin;
}
start:
cout << "Here are your final stats:\n\n";
cout << "Strength: " << strength << "\n\n";
cout << "Defence: " << defence << "\n\n";
system("pause");
cout << "\n\n -- THE ADVENTURE BEGINS --\n\n";
// PART ONE.
cout << "You reach a road, do you want to turn left or right ?\n\n";
cout << "1, Left: Danger, 30percent. Stat Potential Increase, 30ppercent\n\n";
cout << "2, Right: Danger, 60percent. Stat Potential, 70percent \n\n";
cout << "Enter choice (1 or 2): ";
cin >> choice2;
cout << "\n";
switch(choice2) {
case 1:
pot1 = 5;
if(pot1 == 4)
{
cout << "You encounter no dangers, your stats remain the same\n\n";
}
else
{
cout << "-------Start of Battle------";
cout << "\n\n\n";
cout << "You encountered a Black Bear (Level 15)\n";
cout << "\nStrength is: " << strength << "...Defence is: " << defence;
stat = strength + defence;
cout << "\n\n";
cout << "Stats equal: " << stat;
cout << stat;
if(stat > 15)
{
pot3 = rand() % 11;
printf("%d\n", pot3);
{ if(pot3 > 1)
{
cout << "\n You won the battle !";
outcome = 1;
}
else
{
cout << "\n You lost the battle !";
outcome = 0;
}
}
}
{
if(stat < 15)
{
pot4 = rand() % 11;
printf("%d\n", pot4);
{ if(pot4 < 8) {
cout << "\n You Lost the battle !";
outcome = 0;
}
else
{
cout << "\n You won the battle !";
outcome = 1;
}
}
cout << "\n\n\n";
cout << "-------end of battle-------";
cout << "\n\n\n";
if(outcome == 1) {
cout << "\n\n\Your win your first epic battle fight with a Bear !";
strength = strength + 3;
defence = defence + 3;
cout << "Your strength is now: " << strength << ",Your defence is now: " << defence;
}
else
{
cout << "You lost you first epic battle fight with a Bear !";
strength = strength + 0;
defence = defence + 0;
cout << "Your strength is now: " << strength << ",Your defence is now: " << defence;
}
}
break;
case 2:
pot2 = rand() % 11;
printf("%d\n", pot2);
cout << "\n";
if(pot2 < 4)
{
cout << "You encounter no dangers, your stats remain the same \n\n";
}
else
{
cout << "You encountered a Black Bear (Level 20) \n\n";
cout << "Your total stat is: " << strength + defence;
cout << "\n\n";
cout << "You win this battle.." << "Strength + 3, Defence + 3";
cout << "\n\n";
strength = strength + 3;
defence = defence + 3;
cout << "Your strength is now: " << strength << " Your defence is now: " << defence;
}
}
}
}
cout << "\n\n";
system("pause");
return 0;
}