How do I disable a function I don't want to use?
Jun 7, 2013 at 3:34am UTC
How do I not use a function I don't want to use so I can test the one I want without having to go through all of them? I was thinking I could just take it out of my main function, but when I do that I just get return 0; when I build and run my project.
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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
#include <iostream>
#include <string>
#include<conio.h>
#include <cstdlib>
#include <ctime>
#include<iomanip>
#include <Windows.h>
using namespace std;
class INWIN{
public :
void menu(){
cout << "Welcome to Adventure Time! The game with the strongest graphics engine known to man, imagination!" << endl;
cout << "[P]lay\n" << "[Q]uit" << endl;
cin >> choice;
system("cls" );
switch (choice){
case 'P' :
case 'p' :
cout << "Excellent choice! Please name your character" << endl;
cin >> name;
system("cls" );
cout << name << " correct? y/n" << endl;
cin >> choice;
case 'Q' :
case 'q' :
// Make a quit system
break ;
}
for (int x = 0; x<5; ){
switch (choice){
case 'Y' :
system("cls" );
x = 51;
break ;
case 'y' :
system("cls" );
x = 51;
break ;
}
switch (choice){
case 'N' :
system("cls" );
cout << "Please enter a name" << endl;
cin >> name;
system("cls" );
cout << name << " correct? y/n" << endl;
cin >> choice;
if (choice == 'Y' ){
system("cls" );
x = 51;
}
if (choice == 'y' ){
system("cls" );
x = 51;
}
if (choice == 'N' ){
x = 0;
}
if (choice == 'n' ){
x = 0;
}
break ;
case 'n' :
system("cls" );
cout << "Please enter a name" << endl;
cin >> name;
system("cls" );
cout << name << " correct? y/n" << endl;
cin >> choice;
if (choice == 'Y' ){
system("cls" );
x = 51;
}
if (choice == 'y' ){
system("cls" );
x = 51;
}
if (choice == 'N' ){
x = 0;
}
if (choice == 'n' ){
x = 0;
}
break ;
} //switch
} // loop
} // function menu
void classes(){
for (int x2 = 0; x<5;){
cout << "Choose a class:" << endl;
cout << "\n" ;
cout << "[1] Heavy Warrior\n" << "Stats: \n" << "Health: 150 \n" << "Attack: 5 \n" << "Defence: 15 \n" << "Dodge Chance: 5%" << endl;
cout << "\n" ;
cout << "[2] Light Warrior\n" << "Stats: \n" << "Health: 125 \n" << "Attack: 10 \n" << "Defence: 10 \n" << "Dodge Chance: 10%" << endl;
cout << "\n" ;
cout << "[3] Archer\n" << "Stats: \n" << "Health: 100\n" << "Attack: 15 \n" << "Defence: 5 \n" << "Dodge Chance: 15%" << endl;
cin >> choice;
switch (choice){
case '1' :
cout << "Are you sure you want to be a Heavy Warrior? y/n" << endl;
cin >> choice;
switch (choice){
case 'Y' :
case 'y' :
cout << "Your class is now set to Heavy Warrior" << endl;
playerHP = 150;
attack = 5;
defence = 15;
dodgechance = 5;
level = 1;
exp = 0;
x = 51;
cout << "Name: \n" << name << "Class: Heavy Warrior \n" << "Attack: " << attack << "\nDefence: " << defence << "\nDodge Chance:" << dodgechance << "%" << endl;
break ;
case 'N' :
case 'n' :
x = 0;
break ;
} //nested switch
break ;
case '2' :
cout << "Are you sure you want to be a Light Warrior? y/n" << endl;
cin >> choice;
switch (choice){
case 'Y' :
case 'y' :
cout << "Your class is now set to Light Warrior" << endl;
playerHP = 125;
attack = 10;
defence = 10;
dodgechance = 10;
level = 1;
exp = 0;
x = 51;
cout << "Name: \n" << name << "Class: Light Warrior \n" << "Attack: " << attack << "\nDefence: " << defence << "\nDodge Chance:" << dodgechance << "%" << endl;
break ;
case 'N' :
case 'n' :
x = 0;
break ;
} // nested switch
case '3' :
cout << "Are you suer you want to be a Archer? y/n" << endl;
cin >> choice;
switch (choice){
case 'Y' :
case 'y' :
cout << "Your class is now set to Archer" << endl;
playerHP = 100;
attack = 15;
defence = 5;
dodgechance = 15;
level = 1;
exp = 0;
x = 51;
cout << "Name: \n" << name << "Class: Archer \n" << "Attack: " << attack << "\nDefence: " << defence << "\nDodge Chance:" << dodgechance << "%" << endl;
break ;
case 'N' :
case 'n' :
x = 0;
break ;
}
} //main switch
}
} // function classes
private :
char choice;
string name;
int playerHP;
int defence;
int attack;
int level;
int exp;
int dodgechance;
int x;
int x2;
};
int main(){
INWIN MMobj;
MMobj.menu();
MMobj.classes();
}
Last edited on Jun 7, 2013 at 4:27am UTC
Jun 7, 2013 at 4:04am UTC
I'm really not sure what you're asking, but if what I think you're saying is correct, just comment out the function code.
Jun 7, 2013 at 4:07am UTC
How exactly does your program look like...?
Jun 7, 2013 at 4:26am UTC
I posted the code, I only want the classes function to run, but when I take out the menu function it doesn't work, it only shows return 0
Jun 7, 2013 at 4:37am UTC
Try initializing INWIN::x in the constructor.
1 2 3 4 5 6 7 8
//INWIN constructor; no return type
INWIN::INWIN(): //This is called an initializer list
choice('0' ),
name("" ),
//...
x(0),
x2(0)
{}
Maybe the junk value in x is larger than 5 as you test it in your first for loop.
Topic archived. No new replies allowed.