Card dealing program

This is my project im fairly new and found this and thought id try it, how would i go about starting this program? this is a template and i have to finish the program using the comments below...please help

#include <iostream>
#include <ctime>
#include <string>

using namespace std;

//function prototypes
string GetSuit(); // get the card suit (clubs, spades, diamonds, hearts)
int GetFaceValue(); // return a number from 0 to 13 representing the value of the card
string ConvertToCard(int); // convert a number from 0 to 13 into ace, one, two, ..., queen, king

int main()
{
string suit;
int facevalue;
string card;
srand(static_cast<int>(time(0))); // seed the random number generator

cout << "This program will randomly generate 10 playing cards." << endl;
for (int i=1; i<=10; i++)
{
// Fill in the code required to set the variable suit to a random suit value
// by calling function GetSuit

// Fill in the code required to set the variable facevalue to a random number
// from 0 to 13 by calline function GetFaceValue

// Fill in the code required to set the variable card to a string that represents
// the actual card by calling function ConvertToCard and sending it facevalue

cout << "Card " << i << " is the " << card << " of " << suit << endl;
}

return 0;
}

string GetSuit()
{
int num;
string result;
num = (1 + rand() % 4);
switch (num)
{
case 1: result = "clubs";
break;
case 2: result = "spades";
break;
case 3: result = "diamonds";
break;
default: result = "hearts";
}
return result;

}

int GetFaceValue()
{

return rand() % 14;
}

string ConvertToCard(int v)
{
string result;
switch (v)
{
case 0: result = "ace";
break;
case 1: result = "one";
break;
case 2: result = "two";
break;
case 3: result = "three";
break;
case 4: result = "four";
break;
case 5: result = "five";
break;
case 7: result = "seven";
break;
case 8: result = "eight";
break;
case 9: result = "nine";
break;
case 10: result = "ten";
break;
case 11: result = "jack";
break;
case 12: result = "queen";
break;
default: result = "king";
}
return result;
}
Last edited on
Don't double post!
http://www.cplusplus.com/forum/general/94019/

As for needing help, you have all the code you need! You just need to save the return values in to variables and pass one to the last function!
sorry about that, and when i say new i mean new, an example of what you just stated would help
thanks
When a function returns a value, you save it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

int getNumber()
{
    return ( 7 );
}

int main()
{
    int myNumber;

    // myNumber will be the return value.
    myNumber = getNumber();

    std::cout << "Your number is " << myNumber;

    return 0;
}
Your number is 7
Last edited on
closed account (3qX21hU5)
Or you could look into passing by reference.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

using namespace std;

int changeToZero(int &n)
{
    // Directly changes whatever integer you pass as n
    n = 0;
}

int main()
{
    int myNumber = 5;
    cout << "The number is: " << myNumber << endl;

    changeToZero(myNumber);

    cout << "Now the number is: " << myNumber << endl;
    return 0;
}


The number is: 5
Now the number is: 0
Last edited on
This is part of his assignment though, so I'm guessing he is not allowed. (:
Topic archived. No new replies allowed.