Returning INT Through a Class
Mar 28, 2017 at 8:55pm UTC
Morning/Afternoon/Happy Lunch-Time
I'm trying to get it so I can pass an Int into Dice::Hundred and it returns that Int back into Main with a number less than 100. Though It doesn't seem to be returning any number at all. I don't want to label the specific Int thats going to the class because I want to use it multiple times throughout the code, and later in other classes. Any ideas, I'm guessing a keyword is missing somewhere....
Thanks People!
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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
#include <iostream>
#include <string>
#include <ctime>
#include <stdlib.h>
#include <time.h>
// Classes
#include "Character.h"
#include "Dice.h"
#include "Enemies.h"
#include "Stats.h"
using namespace std;
// This Version To Have Skeletons, Stats and Classes!
int main()
{
char name[30];
char dice;
int mainHP;
int mainATK;
/*
string step;
string ans;
string move = "still";
int atk = 0;
int hp = 0;
int pos = 0;
int numseed = 0;
int gamrand;
int gam;
int skelehp = 0;
int skeleatk = 0;
int bosshp = 500;
int bossatk = 9;
int charP = 9;
int bossP = 9;
float charLife = 0;
float bossStr = 0;
int chests [numseed];
srand(time(NULL)); */
// Character Building
// First Convo
cout << "Welcome Young Warrior To The 20 Step Dungeon!" << endl;
cout << "Before We Start... What's Your Name?" << endl;
cin.getline (name,30);
// Dice Objective Construct
Dice Random;
// HP Sats
cout << "Press R For Your Health Points!" << endl;
cin >> dice;
if (dice != 'r' && dice != 'R' ) {
cout << "You've Failed Already.... NEXT!!!" << endl;
return 0;
}
else {
Random.Hundred(mainHP);
dice = 'a' ;
}
cout << "TEST" << mainHP << endl;
// Atk Stats
cout << "Press R For Your Attack Points!" << endl;
cin >> dice;
if (dice != 'r' && dice != 'R' ) {
cout << "You've Failed Already.... NEXT!!!" << endl;
return 0;
}
else {
Random.Hundred(mainATK);
dice = 'a' ;
}
// Start Of Dungeon
}
/*
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
The different color codes are
0 BLACK
1 BLUE
2 GREEN
3 CYAN
4 RED
5 MAGENTA
6 BROWN
7 LIGHTGRAY
8 DARKGRAY
9 LIGHTBLUE
10 LIGHTGREEN
11 LIGHTCYAN
12 LIGHTRED
13 LIGHTMAGENTA
14 YELLOW
15 WHITE
cin.getline (name,20);
*/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#ifndef DICE_H
#define DICE_H
class Dice
{
public :
Dice();
Fifty50();
Hundred(int );
};
#endif // DICE_H
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include <iostream>
#include "Dice.h"
#include <stdlib.h>
#include <time.h>
using namespace std;
Dice::Dice()
{
}
Dice::Fifty50()
{
}
Dice::Hundred(int )
{
cout << "Ahhh their she rolls!" << endl;
return (rand() % 100);
}
Mar 28, 2017 at 9:20pm UTC
class Dice
{
public:
Dice();
Fifty50();
int Hundred();
};
int Dice::Hundred()
{
cout << "Ahhh their she rolls!" << endl;
return (rand() % 100);
}
...
blah = x.Hundred();
Last edited on Mar 28, 2017 at 9:20pm UTC
Mar 30, 2017 at 7:53pm UTC
Thanking you highly ;D
Topic archived. No new replies allowed.