C++ Can someone please help with this code... even when the players number isnt a winning number the program always says the player wins:
#include <stdio.h>
#include <time.h>
//main function
int main()
{
//seeding a random number
srand(time(0));
//define the arrays for the wagered, winning
amount, percent amount
double amounts[7] = { 1, 5, 10, 20, 50, 100, 1000
};
double payoff[7] = { 100, 500, 1000, 2000, 5000,
10000, 100000 };
double percent[7] = { 0.01, 0.05, 1, 2, 5, 10, 100
};
//create a file object to write the
information
FILE *output;
output = fopen("SlotMachineInfo.txt", "w+");
//declare the required variables
int random = 0;
int playerNum, winNum;
double wagared;
double amountWon = 0, jackpot = 10000;
double userAmount = 0, slotPaid = 0, winAmount =
0;
double jackPercent = 0;
int i = 0;
//loop to iterate for 24 hours
for (i = 0; i < 1440; i++)
{
playerNum = rand() % 10;
winNum = rand() % 10;
random = rand() % 7;
wagared = amounts[random];
jackpot += wagared;
fprintf(output, "Jackpot Amount:
%.2lf \n", jackpot);
fprintf(output, "Current bet: %.2lf
\n", wagared);
fprintf(output, "Winning Number: %d
\n", winNum);
fprintf(output, "Player's Number:
%d \n", playerNum);
if (playerNum == winNum)
{
amountWon =
payoff[random];
jackPercent =
jackpot * percent[random] / 100;
if (amountWon
> jackPercent)
{
winAmount = amountWon;
}
else
{
winAmount = jackPercent;
}
slotPaid +=
winAmount;
printf("\nCongrats!\n");
printf("Player
won amount of $ %.2lf \n", winAmount);
}
userAmount += wagared;
fprintf(output, "\n\n");
}
double result = userAmount - slotPaid;
//print the final statement
if (result < 0)
{
fprintf(output, "The amount of
money the casino lost is: $ %.2lf\n", (0 - result));
}
else
{
fprintf(output, "The amount of
money the casino made is: $ %.2lf\n", result);
}
fclose(output);
// the following two statements are optional
// can be avoided.
getchar();
getchar();
return 0;
}
Your program is correct , it is showing win only if the player number matches with the win number.
Pls check the below code , I am printing player number and win number when even any win occurs.
#include <stdio.h>
#include <time.h>
//main function
int main()
{
//seeding a random number
srand(time(0));
//define the arrays for the wagered, winning amount, percent
amount
double amounts[7] = { 1, 5, 10, 20, 50, 100, 1000 };
double payoff[7] = { 100, 500, 1000, 2000, 5000, 10000, 100000
};
double percent[7] = { 0.01, 0.05, 1, 2, 5, 10, 100 };
//create a file object to write the information
FILE *output;
output = fopen("SlotMachineInfo.txt", "w+");
//declare the required variables
int random = 0;
int playerNum, winNum;
double wagared;
double amountWon = 0, jackpot = 10000;
double userAmount = 0, slotPaid = 0, winAmount = 0;
double jackPercent = 0;
int i = 0;
//loop to iterate for 24 hours
for (i = 0; i < 1440; i++)
{
playerNum = rand() % 10;
winNum = rand() % 10;
random = rand() % 7;
wagared = amounts[random];
jackpot += wagared;
fprintf(output, "Jackpot Amount: %.2lf \n", jackpot);
fprintf(output, "Current bet: %.2lf \n", wagared);
fprintf(output, "Winning Number: %d \n", winNum);
fprintf(output, "Player's Number: %d \n", playerNum);
if (playerNum == winNum)
{
amountWon = payoff[random];
jackPercent = jackpot * percent[random] / 100;
if (amountWon > jackPercent)
{
winAmount = amountWon;
}
else
{
winAmount = jackPercent;
}
slotPaid += winAmount;
printf("\nCongrats!\n");
//printing player number and win number
printf("Player Number %d Win Number %d \n",playerNum,winNum);
printf("Player won amount of $ %.2lf \n", winAmount);
}
userAmount += wagared;
fprintf(output, "\n\n");
}
double result = userAmount - slotPaid;
//print the final statement
if (result < 0)
{
fprintf(output, "The amount of money the casino lost is: $
%.2lf\n", (0 - result));
}
else
{
fprintf(output, "The amount of money the casino made is: $
%.2lf\n", result);
}
fclose(output);
// the following two statements are optional
// can be avoided.
getchar();
getchar();
return 0;
}
Pls check this , and let me know if any other issue you have
C++ Can someone please help with this code... even when the players number isnt a winning number the program always says the player wins: #include <stdio.h> #include <time.h> //main functi...
#include<stdio.h> #include<stdlib.h> #include <time.h> int main() { /* first you have to let the computer generate a random number. Then it has to declare how many tries the user has for the game loop. we then need the player to enter their guess. After every guess we have to give an output of how many numbers they have in the right location and how many they have the right number. The player will keep guessing until their 10 tries are...
C program-- the output is not right please help me to correct it. #include <stdio.h> int main() { int arr[100]; int i,j,n,p,value,temp; printf("Enter the number of elements in the array: \n "); scanf("%d",&n); printf("Enter %d elements in the array: \n",n); for(i=0;i<n;i++) { printf("\nelement %d: ",i); scanf("\n%d",&arr[i]); } printf("\nEnter the value to be inserted: \n "); scanf("\n%d",&value); printf("The exist array is: \n"); for(i=0;i<n;i++) { printf("%d",arr[i]); } p=i; for(i=0;i<n;i++) if(value<arr[i] ) { p = i; break; } arr[p]=value; printf("\n"); for (i =...
Can someone help me to convert from c++ to C program int main() { srand(time(0)); int playAgain; int PlayerScore=0; int computerScore= 0; int ties= 0; do { system("CLS"); Firstturn = rand()%(2-1+1)+1;// starting person. ComputerRandomPosition= rand()%(9-1+1)+1;// computer first pick- random gameWin=3; block1= '1'; block2= '2'; block3= '3'; block4= '4'; block5= '5'; block6= '6'; block7= '7'; block8= '8'; block9= '9'; //start of program cout<<"Welcome to Tic Tac Toe Game"<<endl<endl; cout<<"Player:"<<playerScore<<"Computer:"<<computerScore<<"Ties:"<<ties<<endl; if(Firstturn==1)// player first { cout<<"Please Select your a grid to place (X):"<<endl<<endl;...
C Programming The following code creates a deck of cards, shuffles it, and deals to players. This program receives command line input [1-13] for number of players and command line input [1-13] for number of cards. Please modify this code to deal cards in a poker game. Command line input must accept [2-10] players and [5] cards only per player. Please validate input. Then, display the sorted hands, and then display the sorted hands - labeling each hand with its...
Code that needs to be modified: #include #include #include int main() { int i,N,x; unsigned int seed; double R; printf("\nEnter number of iterations and seed"); printf("\n"); scanf("%i %u", &N,&seed); srand(seed); for(i=0;i { R=(double)rand()/RAND_MAX; if (R<0.5) x=x+1; else x=x-1; } printf("Final location is "); printf("%d",x); printf("\n"); } Question: Write a code that generates N pairs of random numbers. Call the first member of each pair x and the second member y. Count how many of the N pairs obey x^2+y^2<1. Call...
I need a basic program in C to modify my program with the following instructions: Create a program in C that will: Add an option 4 to your menu for "Play Bingo" -read in a bingo call (e,g, B6, I17, G57, G65) -checks to see if the bingo call read in is valid (i.e., G65 is not valid) -marks all the boards that have the bingo call -checks to see if there is a winner, for our purposes winning means...
PROGRAMING IN C. PLEASE HELP FIX MY CODE TO FIT THE FOLLOWING CRITERIA: 1.)Read your stocks from your mystocks.txt file. You can use this information for the simulator. 2.)The stock price simulator will return the current price of the stock. The current prices is the prices of the requested ticker + a random number. 3.)We will assume that the stock price remains constant after the price check till your trade gets executed. Therefore, a buy or a sell order placed...
Need help for C program. Thx #include <stdio.h> #include <string.h> #include <ctype.h> // READ BEFORE YOU START: // This homework is built on homework 06. The given program is an updated version of hw06 solution. It begins by displaying a menu to the user // with the add() function from the last homework, as well as some new options: add an actor/actress to a movie, display a list of movies for // an actor/actress, delete all movies, display all movies,...
C LANGUAGE. PLEASE INCLUDE COMMENTS :) >>>>TheCafe V2.c<<<< #include <stdio.h> int main() { int fries; // A flag denoting whether they want fries or not. char bacon; // A character for storing their bacon preference. double cost = 0.0; // The total cost of their meal, initialized to start at 0.0 int choice; // A variable new to version 2, choice is an int that will store the // user's menu choice. It will also serve as our loop control...
Please do in C please. Edit sliding.c. Comments on code would be nice. Thank you. Here is main.c #include "sliding.h" #include <malloc.h> #include <stdlib.h> //Prints grid in row major order. Tries to ensure even spacing. void print_grid(int * my_array, int rows, int cols){ int i,j; for(i=0; i<rows; i++){ for(j=0; j<cols; j++){ if(my_array[i*cols + j]!=-1){ printf(" %d ", my_array[i*cols + j]); } else{ printf("%d ", my_array[i*cols + j]); } } printf("\n"); } } int main(int argc, char *argv[]) { int seed,rows,cols;...