Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <unistd.h>
- /* PART 1
- int multByTwo(int mynum){
- return mynum*2;
- }
- int isFirstBigger(int mynum, int mynum2){
- if (mynum > mynum2){
- return 1;
- }
- return 0;
- }
- float addVat(float mynum){
- return mynum*1.2;
- }
- */
- void whlcheck(char *whl, int length){
- int win = 0;
- int jackpot = 1;
- char check[length];
- for(int i = 0; i<length; i++){
- check[i] = whl[i];
- for(int j = 0; j<length; j++){
- if(j!=i){
- if (whl[j] == check[i]){
- win = 1;
- }
- else{
- jackpot = 0;
- }
- }
- }
- }
- if(win){
- if(jackpot){
- printf("Jackpot!\n");
- }
- printf("You win!\n");
- }
- else{
- printf("Unlucky, You lose!\n");
- }
- }
- void printwhl(char *whl, int length){
- char* newwhl[length];
- for(int i = 0; i<length; i++){
- if (whl[i] == 'B'){
- newwhl[i] = "Bell";
- }
- if (whl[i] == 'O'){
- newwhl[i] = "Orange";
- }
- if (whl[i] == 'C'){
- newwhl[i] = "Cherry";
- }
- if (whl[i] == 'H'){
- newwhl[i] = "Horseshoe";
- }
- }
- printf("\n\n%s", newwhl[0]);
- for(int i = 1; i<length; i++){
- printf(" - %s",newwhl[i]);
- }
- printf("\n");
- whlcheck(whl, length);
- }
- void spinwhl(int length){
- char symbols[4] = {'B', 'O', 'C', 'H'};
- char whl[length];
- int check = 0;
- while(check<100){
- for(int i = 0; i<length; i++){
- whl[i] = symbols[(rand() % 4)];
- }
- printf("\e[1;1H\e[2J");
- printf("%c", whl[0]);
- for(int i = 1; i<length; i++){
- printf("|%c",whl[i]);
- }
- printf("\n");
- check++;
- usleep(10000);
- }
- printwhl(whl, length);
- }
- void main(){
- int whllength;
- srand(time(NULL));
- printf("Bell - B\nOrange - O\nCherry - C\nHorseshoe - H\n\nHow many reels would you like?\n");
- scanf("%i", &whllength);
- spinwhl(whllength);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement