Classes, setters, and getter.

Hey yall,
I'm currently working on a program that tells you which card you have. its value and the suit. i'm not sure why it doesn't compile. Do keep in mind I have little knowledge as this is my second c++ class ever taken.

here is the code:


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

using namespace std;

// ****creating class****
class Card
{

private:
int value; // to hold value of
char suit; // to hold value of
public:
void setValue(int v); // inline function to
{value= v;}
void setSuit(char s); // inline function to
{suit = s;}


int getValue(); // inline function to
{return value}
char getSuit(); // inline function to
{return suit;}

void display();

};




void Card::display()
{



switch(getSuit())
{
case'h':
case'H': cout << " The suit of your card is hearts \n";
break;
case's':
case'S': cout << " The suite of your cars is spades \n";
break;
case'd':
case'D': cout << " The suite of your card is diamonds \n";
break;
case'c':
case'C': cout << " The suite of your card is clubs \n";
break;
}




cout << "The value of your card is: " << getValue() << "\n";

}


//****************** MAIN ***************

int main()
{
Card idk;
int num;
char letter;

cout << "Hello... What is the first letter of the suit of your card? ";
cin >> letter;


//while ( char != 'h' || char != 'H' || char != 'c' || char != 'C' || char != 'd' || char != 'D' || char != 's' || char 'S' )
//{
//"You have entered an invalid letter... Please try again. ";
//cin >> letter;
//}


idk.setSuit(letter);


cout << "Now please enter the value of your card... \n";
cout << "Remember, Ace is 1, Jack is 11, Queen is 12, and King is 13: ";
cin >> num;



while (num < 1 || num > 13)
{
cout << "You can't follow instructions... \n";
cout << "Please enter a correct number: ";
cin >> num;
}




idk.setValue(num);

idk.display();


system("pause");
return 0;
}

1
2
int getValue(); // inline function to
{return value}


Missing a semicolon.

You cant do stuff like this -
1
2
3
4
int getValue(); // inline function to
{return value}
char getSuit(); // inline function to
{return suit;}


You cant add a semicolon to the declaration and then define it.

Edit: Compiles fine now :)
Last edited on
i fixed it and its still not compiling :(
Can you provide the code again? And please use code tags, they are under format - http://www.cplusplus.com/articles/jEywvCM9/
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
#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

// ****creating class****
class Card
{

private: 
	int value;      // to hold value of
	char suit;         // to hold value of
public:
	void setValue(int v); // inline function to
			{value= v;}
	void setSuit(char s);   // inline function to
			{suit = s;}
	
			
	int getValue();   // inline function to
			{return value}
	char getSuit();   // inline function to
			{return suit}

	void display();

};




void Card::display()
{



	switch(getSuit())
	{
	case'h':
	case'H': cout << " The suit of your card is hearts \n";
		break;
	case's':
	case'S': cout << " The suite of your cars is spades \n";
		break;
	case'd':
	case'D': cout << " The suite of your card is diamonds \n";
		break;
	case'c':
	case'C': cout << " The suite of your card is clubs \n";
		break;
	}




	cout << "The value of your card is: " << getValue() << "\n";

}


//******************  MAIN  ***************

int main()
{
	Card idk;
	int num;
	char letter;

	cout << "Hello... What is the first letter of the suit of your card? ";
	cin >> letter;


	//while ( char != 'h' || char != 'H' || char != 'c' || char != 'C' || char != 'd' || char != 'D' || char != 's' || char 'S' )
	//{
		//"You have entered an invalid letter... Please try again. ";
		//cin >> letter;
	//}


	idk.setSuit(letter);
	

	cout << "Now please enter the value of your card... \n";
	cout << "Remember, Ace is 1, Jack is 11, Queen is 12, and King is 13: ";
	cin >> num;



	while (num < 1 || num > 13)
	{
		cout << "You can't follow instructions... \n";
		cout << "Please enter a correct number: ";
		cin >> num;
	}
	



	idk.setValue(num);

	idk.display();


	system("pause");
	return 0;
}

Oh I guess you missunderstood what I said. These ones -

1
2
3
4
5
6
7
8
9
10
void setValue(int v); // inline function to
			{value= v;}
	void setSuit(char s);   // inline function to
			{suit = s;}
	
			
	int getValue();   // inline function to
			{return value}
	char getSuit();   // inline function to
			{return suit}


You cant declare a function, use semilcolon and then define it. You have to do it like this -

1
2
3
4
5
6
7
8
9
10
11
12
void setValue(int v) //remove semicolon
	{value= v;}

void setSuit(char s)   //remove semicolon
	{suit = s;}
	
			
int getValue();   //remove semicolon
	{return value;} //  You need to have semicolon after you return something.

char getSuit();   //remove semicolon
	{return suit;} // You need to have semicolon after you return something. 
Awesome! thank you so much. i couldn't figure out why it wasn't compiling :)
Very welcome my friend. Goodluck to you.
Topic archived. No new replies allowed.