-3
switch 문을 사용하는 간단한 프로젝트. 4 가지 선택 사항이 있으며 1 ~ 3 가지 기능이 뛰어납니다. switch 문 (case 4, duh)의 네 번째 선택 사항은 사용자에게 "감사합니다!"라는 메시지를 표시 한 다음 몇 초 후에 읽을 수 있도록 프로그램을 끝내야합니다. 나는 "고마워!" xD 부분.프롬프트가 표시되면 몇 초 후에 프로그램을 끝내시겠습니까?
나는 자동으로 프로그램을 종료하는 법을 모른다. 나는 출구 (0) 함수와 행운을 시도했다. 또한 메시지가 닫히기 전에 몇 초 동안 메시지를 표시해야합니다.
/* -------------------------------------------------
The purpose of this program is to simulate a
basic ATM machine and display four key options:
deposit, withdraw, check balance, and exit.
A switch statement must be used.
------------------------------------------------ */
#include <stdio.h>
#include <stdlib.h>
int main()
{
// Assume a balance of $500.00 for all users.
#define BALANCE 500.00
// Declare variables.
int iMenuSelect = 0;
double dUserDeposit = 0.0, dNewBalance = 0.0;
double dUserWithdraw = 0.0;
//Print the menu to the console.
printf("\t*******************\n");
printf("\t1 - Deposit\n");
printf("\t2 - Withdraw\n");
printf("\t3 - Check Balance\n");
printf("\t4 - Exit\n");
printf("\t*******************\n\n");
//Prompt the user for their selection and store the value.
printf("Please type the number of the option you would like to perform > ");
scanf("%d", &iMenuSelect);
//Begin switch statement of variable iMenuSelect.
switch(iMenuSelect)
{
// Deposit, create new balance.
case 1:
// Ask for deposit amount, then add it and print new balance.
printf("\nHow much would you like to deposit? > ");
scanf("%lf", &dUserDeposit);
// Create and display new balance after deposit.
dNewBalance = dUserDeposit + BALANCE;
printf("\nYour new balance is $%.2f.\n", dNewBalance);
break;
// Withdraw, create new balance.
case 2:
// Ask for withdraw amount, then subtract it and print new balance.
printf("\nHow much would you like to withdraw? > ");
scanf("%lf", &dUserWithdraw);
// Create and display new balance.
dNewBalance = BALANCE - dUserWithdraw;
if(dUserWithdraw <= 500)
{
printf("\nHere is your money. Your new balance is $%.2f.\n", dNewBalance);
}
else
{
printf("\nYou have insufficient funds.\n");
}
break;
// Check balance, display BALANCE.
case 3:
// Display balance.
printf("\nYour balance is %.2f\n", BALANCE);
break;
// Exit program.
case 4: exit(EXIT_FAILURE);
break;
default: printf("\n\nWARNING: Invalid option selected.\n\n");
}
return 0;
}
편집 2016년 11월 19일 : 여기
코드의난 그냥 사용할 수도 시스템 ("PAUSE"); 종료 할 때 사용자가 입력하기를 기다렸다. 나는 이것을 게시 한 이후로 프로그래밍에 훨씬 능숙 해졌다. 사이트를 어수선하게해서 죄송합니다.
코드 없이는 ... –
참조 용 코드를 첨부 해주십시오. [디버깅 도움말에 대한 최소 및 검증 가능한 예제 완성] (http://stackoverflow.com/help/mcve)의 지침을 확인하십시오. –
"* show *"및 "* close *" "* message *"? 어떤 윈도우 시스템을 사용하고 있습니까? – alk