2017-10-14 26 views
1
#define _CRT_SECURE_NO_WARNINGS 
/* 

Objectif: Ce programme permet à l'utilisateur de parier sur des chevaux dans une course pour gagner de l'argent sur ledit paris. J'essaye d'exécuter la fonction configureBalance et puis ajoute de l'argent à la balance. Je reçois une violation d'accès en lecture d'exception */Passer la valeur de cette fonction

#include <stdio.h> 
#include <stdlib.h> 
#define PAUSE system("pause") 
#define CLS system("cls") 
#define FLUSH myFlush() 

//Prototyping 
void getChoice(char *userChoice);  // main menu choice 
void displayMenu();    // visual menu 
void myFlush();      // flush 
void configureBalance(int *balance, int *wallet, int *withdraw, int *deposit); // this function is for editing account credentials 
void currentBalance(int *balance);   // displays the account balance 
void coolRaceVisual();    // cool looking visual 
           //Structs 


main() { 
int balance = 0, wallet = 0, withdraw = 0, deposit = 0; 
char choice = ' '; 


do { 
    getChoice(&choice); 

    switch (choice) { 

    case 'A': 
     configureBalance(balance, wallet, withdraw, deposit); 
     PAUSE; 
     break; 

    case 'B': 
     coolRaceVisual(); 
     PAUSE; 
     break; 
    case 'Q': 
     CLS; 
     printf("[][][][][][][][][][][]\n"); 
     printf("[]  Goodbye ! []\n"); 
     printf("[][][][][][][][][][][]\n"); 

     break; 

    default: 
     printf("[][][][][][][][][][][][][][][][][][][][][][][]\n");// 
     printf("[] Invalid Selection! Please try again []\n");// This 
prompt shows up when the user 
     printf("[][][][][][][][][][][][][][][][][][][][][][][]\n");//  
inputs something incorrectly 
     PAUSE; 
     CLS; 
     break; 
     return; 
    } 

} while (choice != 'Q'); 
PAUSE; 
}//end main 

void getChoice(char *userChoice) { 
displayMenu(); 
scanf("%c", userChoice); FLUSH; 
*userChoice = toupper(*userChoice); 
}//end getChoice 

void displayMenu() { 
CLS; 

printf("     Horse Derby Ticket Office    \n"); 
printf("               \n"); 
printf("  A) Configure Balances.        \n"); 
printf("               \n"); 
printf("  B) Watch the Race.         \n"); 
printf("               \n"); 
printf("  C) View Race Records.        \n"); 
printf("               \n"); 
printf("  D) Save and Quit.         \n"); 
printf("               \n"); 
printf("  Q) Quit.            \n"); 
printf("               \n"); 
}// end displayMenu 

void myFlush() { 
while (getchar() != '\n'); 
}//end myFlush 

void configureBalance(int *balance, int *wallet, int *withdraw, int *deposit) { 
CLS; 
char configureMenuChoice = ' '; 

printf("What service would you like? (Not FDIC Insured)\n\n"); 

printf("A) Add funds to your account balance.\n"); 
printf("B) Withdraw funds to your wallet.\n"); 
printf("C) Check Account Balance.\n"); 
printf("\n\n"); 
scanf("%c", &configureMenuChoice); 
configureMenuChoice = toupper(configureMenuChoice); 

majuscules le choix de la configuration des soldes

if (configureMenuChoice == 'A') { 
    CLS; 
    printf("How much would you like to add to your account balance? \n"); 

Cela ajoute directement à l'équilibre

scanf("%i", &deposit); 
    *balance = *balance + *deposit; 
} 
if (configureMenuChoice == 'C') { 
    CLS; 
    currentBalance(*balance);      // displays current balance, made a functino so it can be used at will 
} 
}//end conFigureBalance 

void currentBalance(int *balance) { 

printf("Your current balance is: %i\n", &balance); 

}//end checkBalance 
+0

@Deonte Threatt Il doit y avoir scanf ("% i", dépôt); au lieu de scanf ("% i", & dépôt); dans la fonction. –

Répondre

1

Modifier ceci:

scanf("%i", &deposit); 

à ceci:

scanf("%i", deposit); 

depuis deposit est de type int* dans ce contexte (le corps de la fonction configureBalance).

C'est la même logique que celle suivie ici: scanf("%c", userChoice);, alors je me demande comment vous l'avez manqué.

+0

J'ai changé cela mais dans les valeurs quand j'ajoute le dépôt à la balance. –