Jump to content

Why wont this work!? (C++)

Aaanum1
Go to solution Solved by WanderingFool,

The warning is exactly as it sounds.  Your function playerHand1 doesn't return a value.

 

Consider

int myFunction() { //Error}vs.int myFunction2() {    return 1; //No error}

This throws the exact same error.  You notice how it is expecting to return an int, but myFunction doesn't return one.  The myFunction2 however does and will not throw an error.

 

If you don't want a value to be return your declaration should be

 

void playerHand1.....

So I have been trying to write the basics of a Blackjack program in C++, but I keep getting this error. error C4716: 'handGenerator::playerHand1' : must return a value
Here's the code

#include "stdafx.h"

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
class handGenerator{
public:
int playerHand1()
{
int aceChoice;
int cardPlayer1 = rand()%13;
switch (cardPlayer1) {
case 1:
cout << "You have an Ace, do you want it to be 1 or 11?" << endl;
cin >> aceChoice;
break;
case 11:
cardPlayer1 = 10;
break;
case 12:
cardPlayer1 = 10;
break;
case 13:
cardPlayer1 = 10;
};
cout << "Your hand is" << cardPlayer1;
}
};
 
int main() {
 
cout << "Welcome to Richard's game of Blackjack!" << endl;
cout << "What's your name?" << endl;
string name;
cin >> name;
cout << "Hi " << name << endl;
handGenerator playerObj;
playerObj.playerHand1();
                }

Hello. Here are some words.

FX-8150, GTX 670, ASRock 990Fx Extreme4, 8Gb Patriot RAM, 1TB boot and Storage, Windows 7 64Bit

http://www.gametracker.com/server_info/85.234.146.76:3062/

Link to comment
Share on other sites

Link to post
Share on other sites

The warning is exactly as it sounds.  Your function playerHand1 doesn't return a value.

 

Consider

int myFunction() { //Error}vs.int myFunction2() {    return 1; //No error}

This throws the exact same error.  You notice how it is expecting to return an int, but myFunction doesn't return one.  The myFunction2 however does and will not throw an error.

 

If you don't want a value to be return your declaration should be

 

void playerHand1.....

0b10111010 10101101 11110000 00001101

Link to comment
Share on other sites

Link to post
Share on other sites

The warning is exactly as it sounds.  Your function playerHand1 doesn't return a value.

 

Consider

int myFunction() { //Error}vs.int myFunction2() {    return 1; //No error}

This throws the exact same error.  You notice how it is expecting to return an int, but myFunction doesn't return one.  The myFunction2 however does and will not throw an error.

 

If you don't want a value to be return your declaration should be

 

void playerHand1.....

I don't know how I missed that, thanks.

Hello. Here are some words.

FX-8150, GTX 670, ASRock 990Fx Extreme4, 8Gb Patriot RAM, 1TB boot and Storage, Windows 7 64Bit

http://www.gametracker.com/server_info/85.234.146.76:3062/

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×