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.
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;
#include "stdafx.h"
#include <iostream>
#include <string>
usingnamespace 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.