Question: This is all C++. Everything is running the way it should, but I can only enter whole numbers otherwise the program will crash. I can't

This is all C++. Everything is running the way it should, but I can only enter whole numbers otherwise the program will crash. I can't enter something like 60.65 without it crashing. I just need someone to explain how to get the computer to recognize all the numbers I put in.

#include #include #include #include

using namespace std;

int main() {

int UPPER_BOUND = 30; int guess; int num; int Schmoney; int Addiction;

cout << "How much money do you have in your pocket? $"; cin >> Schmoney;

if (Schmoney < 0) { cout << "You can't have a negative amount of money." << endl; return 0; } //else if (Schmoney == 0) { //cout << "You need money to play" << endl; //return 0; //}

cout << "How much do you want to bet? $"; cin >> Addiction;

if (Addiction < 0) { cout << "It needs to be a positive number." << endl; return 0; } else if (Addiction > Schmoney) { cout << "You don't have enough money to make that bet" << endl; return 0; }

srand(time(0));

num = rand() % UPPER_BOUND + 3;

cout << "What do you think the winning number will be? "; cin >> guess;

if (guess == num) { cout << "The Winning Number is " << num << endl; cout << "You now have $" << Addiction * 2 + Schmoney << " in your pocket." << endl; } else if (guess == num + 1) { cout << "The Winning Number is " << num << endl; cout << "You now have $" << Addiction * 1.5 + Schmoney << " in your pocket." << endl; } else if (guess == num - 1) { cout << "The Winning Number is " << num << endl; cout << "You now have $" << Addiction * 1.5 + Schmoney << " in your pocket." << endl; } else if (guess == num + 2) { cout << "The winning number is " << num << endl; cout << "You now have $" << Addiction + Schmoney << " in your pocket." << endl; } else if (guess == num - 2) { cout << "The winning number is " << num << endl; cout << "You now have $" << Addiction + Schmoney << " in your pocket." << endl; } else if (guess < num) { cout << "The Winning Number is " << num << endl; cout << "You now have $" << Schmoney - Addiction << " in your pocket." << endl; } else if (guess > num) { cout << "The Winning Number is " << num << endl; cout << "You now have $" << Schmoney - Addiction << " in your pocket" << endl; }

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!