Post: why am i getting this error
04-20-2011, 12:59 AM #1
|C++|
< ^ > < ^ >
(adsbygoogle = window.adsbygoogle || []).push({}); #include "stdafx.h"
#include <iostream>

using namespace std;

class player
{
private:
int health;
int speed;
public:
void increaseHealth()
{
health++;
}
void decreaseHealth()
{
health--;
};

class zomb
{
public:
int health1;
int health2;
};

int main()
{
player t;

t.increaseHealth();

t.decreaseHealth();

return 0;

char f;

cin>>f;
}

---------- Post added at 08:57 PM ---------- Previous post was at 08:50 PM ----------

this is the error:

IntelliSense: expected a '}' c:\users\ebanks family\documents\visual studio 2010\projects\yoyo\yoyo\yoyo.cpp 41

---------- Post added at 08:59 PM ---------- Previous post was at 08:57 PM ----------

obviously i have not really done anything with this yet but im experimenting with classes and im stumped by this error
04-20-2011, 01:38 AM #2
schnzrs
Do a barrel roll!
Add another } at the end of your program.
04-20-2011, 02:09 AM #3
3arc
Meow.
Here: I formatted and fixed it up a bit for you. that should work. You forgot a brace after the decreaseHealth function declaration.

    
#include "stdafx.h"
#include <iostream>

using namespace std;

class player {
private:
int health;
int speed;
public:
void increaseHealth()
{
health++;
}
void decreaseHealth()
{
health--;
}
}

class zomb {
public:
int health1;
int health2;
};

int main() {
player t;
t.increaseHealth();
t.decreaseHealth();
return 0;
char f;
cin>>f;
}
04-20-2011, 05:29 AM #4
|C++|
< ^ > < ^ >
Originally posted by 3arc View Post
Here: I formatted and fixed it up a bit for you. that should work. You forgot a brace after the decreaseHealth function declaration.

    
#include "stdafx.h"
#include <iostream>

using namespace std;

class player {
private:
int health;
int speed;
public:
void increaseHealth()
{
health++;
}
void decreaseHealth()
{
health--;
}
}

class zomb {
public:
int health1;
int health2;
};

int main() {
player t;
t.increaseHealth();
t.decreaseHealth();
return 0;
char f;
cin>>f;
}


wow thank you, but i already re wrote it already..but can you fix this ... i cant get the speed and health to do what they are supposed to do. the first line works ex:if i put 2 it will give me 3 which is correct but the other lines give me some super crazy number...debug this and see what im trying to say.
    #include "stdafx.h"
#include<iostream>

using namespace std;

class Player
{
public:
int health;
int speed;
public:
void increaseHealth()
{
health++;
cout<<"my health is now "<<health;
}
void decreaseHealth()
{
health--;
cout<<"my health is now "<<health;
}
void increaseSpeed()
{
speed++;
cout<<"my speed is now "<<speed;
}
void decreaseSpeed()
{
speed--;
cout<<"my speed is now "<<speed;
}
};

class zombies
{
public:
int health;
int speed;
public:
void increaseHealth()
{
health++;
cout<<"my health is now "<<health;
}
void decreaseHealth()
{
health--;
cout<<"my health is now "<<health;
}
void increaseSpeed()
{
speed++;
cout<<"my speed is now "<<speed;
}
void decreaseSpeed()
{
speed--;
cout<<"my speed is now "<<speed;
}
};

int main()
{
int h;
Player a;
Player b;
Player c;
Player d;
for(int j=1;j<10;j++)
{
a.health = 1;
b.speed = 1;
a.increaseHealth();
cout<<endl;
b.decreaseHealth();
cout<<endl;
c.increaseSpeed();
cout<<endl;
d.decreaseSpeed();
cin>>h;
}
return 0;
char f;
cin>> f;
}
04-20-2011, 02:33 PM #5
Originally posted by SLiiTH3R View Post
wow thank you, but i already re wrote it already..but can you fix this ... i cant get the speed and health to do what they are supposed to do. the first line works ex:if i put 2 it will give me 3 which is correct but the other lines give me some super crazy number...debug this and see what im trying to say.
    #include "stdafx.h"
#include<iostream>

using namespace std;

class Player
{
public:
int health;
int speed;
public:
void increaseHealth()
{
health++;
cout<<"my health is now "<<health;
}
void decreaseHealth()
{
health--;
cout<<"my health is now "<<health;
}
void increaseSpeed()
{
speed++;
cout<<"my speed is now "<<speed;
}
void decreaseSpeed()
{
speed--;
cout<<"my speed is now "<<speed;
}
};

class zombies
{
public:
int health;
int speed;
public:
void increaseHealth()
{
health++;
cout<<"my health is now "<<health;
}
void decreaseHealth()
{
health--;
cout<<"my health is now "<<health;
}
void increaseSpeed()
{
speed++;
cout<<"my speed is now "<<speed;
}
void decreaseSpeed()
{
speed--;
cout<<"my speed is now "<<speed;
}
};

int main()
{
int h;
Player a;
Player b;
Player c;
Player d;
for(int j=1;j<10;j++)
{
a.health = 1;
b.speed = 1;
a.increaseHealth();
cout<<endl;
b.decreaseHealth();
cout<<endl;
c.increaseSpeed();
cout<<endl;
d.decreaseSpeed();
cin>>h;
}
return 0;
char f;
cin>> f;
}


The first one works becuase you specefied that a.health = 1; so its going to start at one and add to it. For the rest like b.health, c.speed, d.speed you never specefied a starting value like 1 as you did like in the a.health so its returning randomly high values. Also you have to specify the values outide the loop. Right now, when it loops it begins by setting a.health = 0, so your always going to get the SAME value when it loops and adds to it, here is your code fixed and I think its what you are looking for:

    
#include<iostream>

using namespace std;

class Player
{
public:
int health;
int speed;
public:
void increaseHealth()
{
health++;
cout<<"my health is now "<<health;
}
void decreaseHealth()
{
health--;
cout<<"my health is now "<<health;
}
void increaseSpeed()
{
speed++;
cout<<"my speed is now "<<speed;
}
void decreaseSpeed()
{
speed--;
cout<<"my speed is now "<<speed;
}
};

class zombies
{
public:
int health;
int speed;
public:
void increaseHealth()
{
health++;
cout<<"my health is now "<<health;
}
void decreaseHealth()
{
health--;
cout<<"my health is now "<<health;
}
void increaseSpeed()
{
speed++;
cout<<"my speed is now "<<speed;
}
void decreaseSpeed()
{
speed--;
cout<<"my speed is now "<<speed;
}
};

int main()
{
int h;
Player a;
Player b;
Player c;
Player d;
a.health = 1;
b.health = 0;
c.speed = 0;
d.speed = 0;
for(int j=1;j<10;j++)
{
a.increaseHealth();
cout<< endl;
b.decreaseHealth();
cout<< endl;
c.increaseSpeed();
cout<< endl;
d.decreaseSpeed();
cout<< "\n\n" << endl;
cin>>h;
}
return 0;
char f;
cin>> f;
}

Last edited by MoBaTeY ; 04-20-2011 at 02:36 PM.

The following user thanked MoBaTeY for this useful post:

|C++|
04-20-2011, 03:35 PM #6
|C++|
< ^ > < ^ >
Originally posted by MoBaTeY View Post
The first one works becuase you specefied that a.health = 1; so its going to start at one and add to it. For the rest like b.health, c.speed, d.speed you never specefied a starting value like 1 as you did like in the a.health so its returning randomly high values. Also you have to specify the values outide the loop. Right now, when it loops it begins by setting a.health = 0, so your always going to get the SAME value when it loops and adds to it, here is your code fixed and I think its what you are looking for:

    
#include<iostream>

using namespace std;

class Player
{
public:
int health;
int speed;
public:
void increaseHealth()
{
health++;
cout<<"my health is now "<<health;
}
void decreaseHealth()
{
health--;
cout<<"my health is now "<<health;
}
void increaseSpeed()
{
speed++;
cout<<"my speed is now "<<speed;
}
void decreaseSpeed()
{
speed--;
cout<<"my speed is now "<<speed;
}
};

class zombies
{
public:
int health;
int speed;
public:
void increaseHealth()
{
health++;
cout<<"my health is now "<<health;
}
void decreaseHealth()
{
health--;
cout<<"my health is now "<<health;
}
void increaseSpeed()
{
speed++;
cout<<"my speed is now "<<speed;
}
void decreaseSpeed()
{
speed--;
cout<<"my speed is now "<<speed;
}
};

int main()
{
int h;
Player a;
Player b;
Player c;
Player d;
a.health = 1;
b.health = 0;
c.speed = 0;
d.speed = 0;
for(int j=1;j<10;j++)
{
a.increaseHealth();
cout<< endl;
b.decreaseHealth();
cout<< endl;
c.increaseSpeed();
cout<< endl;
d.decreaseSpeed();
cout<< "\n\n" << endl;
cin>>h;
}
return 0;
char f;
cin>> f;
}


i knew i didnt define em all but i purposely defined 2 of them to test, and being that i defined 2 i should get two valid responses....no? anyways thnx....plz check out this thread i need help.... again. You must login or register to view this content.

---------- Post added at 11:35 AM ---------- Previous post was at 11:34 AM ----------

Originally posted by 3arc View Post
Here: I formatted and fixed it up a bit for you. that should work. You forgot a brace after the decreaseHealth function declaration.

    
#include "stdafx.h"
#include <iostream>

using namespace std;

class player {
private:
int health;
int speed;
public:
void increaseHealth()
{
health++;
}
void decreaseHealth()
{
health--;
}
}

class zomb {
public:
int health1;
int health2;
};

int main() {
player t;
t.increaseHealth();
t.decreaseHealth();
return 0;
char f;
cin>>f;
}


need help You must login or register to view this content. plz check it out
04-20-2011, 03:56 PM #7
Originally posted by SLiiTH3R View Post
i knew i didnt define em all but i purposely defined 2 of them to test, and being that i defined 2 i should get two valid responses....no? anyways thnx....plz check out this thread i need help.... again. You must login or register to view this content.

---------- Post added at 11:35 AM ---------- Previous post was at 11:34 AM ----------



need help You must login or register to view this content. plz check it out


Well if you want to make it where they test the ones with values on them, youll have to do like if statements to check for the conditions.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo