c++ program is not working

Write your question here.
I don't know what is wrong with my code. Can you guys help me please?
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
#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;

char getAnswer();
int coinToss();
double bankAccount(int coinToss, char getAnswer);

int main()
{
	double bankAccount = 15.00;
	char choice = 'z';

	cout << "Welcome to the coin flip game." << endl;
	cout << "It will cost you 1 dollar to play" << endl;
	cout << "If you guess correctly, you will match your bet one to one" << endl;
	cout << "Would you like to play? <y/n>." << endl;
	cin >> choice;
	choice = tolower(choice);

	if (choice == 'y')
	{
		getAnswer();

	}
	if (choice == 'n')
	{
		cout << "Thanks for joining!!" << endl;
	}

	getAnswer();
	coinToss();
	bankAccount(); >>>>>>>>// there is something wrong here!

	return 0;
}

char getAnswer()
{
	char guess ;

	cout << "\nWelcome!! Im glad you want to play." << endl;
	cout << "Guess heads or tails and I will tell you if you guessed correctly. <h/t>" << endl;
	cin >> guess;
	guess = tolower(guess);

	if (guess == 'h')
	{
		guess == 1;
	}
	if (guess == 't')
	{
		guess == 0;
	}
	return guess;
}


int coinToss()
{
	srand(static_cast<unsigned int>(time(0)));
	int result = rand() % 2;

	if (result == 0)			// 0 == tails 1 == heads
	{
		cout << "The result was heads." << endl;
	}
	else
	{
		cout << "The result was tails." << endl;
	}
	return result;
}

double bankAccount(int coinToss, char getAnswer)
{
	int bankBalance;
	int guess;
	int result;

	if (result == guess)
	{
		bankBalance == bankBalance + 2;

	}

	if (coinToss != guess)
	{
		bankBalance == bankBalance - 1;
	}
	return bankBalance;
}

Last edited on
You have declared bankAccount with two parameters so in order to call it you would need to pass two arguments.

 
bankAccount(0, '?');
Why do you think there is something wrong with it? What behaviour are you seeing that differs from the behaviour you expect? We're not mind-readers, so it might help if you actually told us what's wrong?

One thing I notice is that nowhere in your main program do you do anything with the return values from your functions.
Hello,

The first thing, how are you compiling (show your compile commmand), turn on compiler warnings.

1
2
3
4
5
int main()
{
    double bankAccount = 15.00;
//then you do 
bankAccount(); >>>>>>>>// there is something wrong here! 

You can't name a variable and call a function with the same name from the same function (main).
Variables only live in the function they are declared in.
There are other errors, but lets get rid of the first one.

Regards
closed account (48T7M4Gy)
don't know what is wrong with my code.

Your code is perfect, there is absolutely nothing wrong with it. Thank you for your request, please green tick it.
As alonso12 stated, you can name name a function and a variable by the same name. I'd suggest you simply change your

double bankAccount = #

into

double bankAccountAmount = #

or something like that so that they differ in some way and don't confuse the computer
Topic archived. No new replies allowed.