. 1 #include <stdio.h> 2 #include < String .h> . 3 // definition of a structure . 4 struct MyAccount { . 5 Double leftMoney; // balance . 6 char AccountDetail [ 3000 ]; // account details 7 }; . 8 . 9 // variables defined global variables associated --- 10 char isOut = ' ' ; . 11 int Loop = . 1 ; 12 is char Key = ' ' ; 13 is Double Money = 0.0 ; // the amount of revenue or expenditure 14 char Item [ 100 ] = " " ; 15 char reason [ 100 ] = " " ; // income or expense described 16 . 17 18 is // registration revenue function . 19 void importRed ( struct myAccount * myAccount) { 20 is // the printf ( "registration revenue \ n-"); BREAK; 21 is the printf ( " Please enter the amount of revenue: " ); 22 is Scanf ( " % LF" , & Money); 23 is the printf ( " Please enter the source of income: " ); 24 Scanf ( " % S " , reason); 25 getchar (); 26 is (* myAccount) + = .leftMoney Money; 27 sprintf (Item, " revenue \ T% .2f \ T \ T% .2f \ T \ T% S \ n- ' , Money, (* myAccount) .leftMoney, reason); 28 strcat ((* myAccount) .accountDetail, Item); 29 } 30 31 is 32 // registration payout function 33 is void outputRed ( struct* MyAccount myAccount) { 34 is the printf ( " Please enter payment was: " ); 35 Scanf ( " % LF " , & Money); 36 getchar (); 37 [ IF (Money> (* myAccount) .leftMoney) { 38 is the printf ( " insufficient balance \ n- ' ); 39 return ; 40 } 41 is the printf ( " Please enter the expenditure destination: " ); 42 is Scanf ( " % S " , reason); 43 is getchar(); 44 (*myaccount).leftMoney -= money; 45 sprintf(item, "支出\t%.2f\t\t%.2f\t\t%s\n", money, (*myaccount).leftMoney, reason); 46 strcat((*myaccount).accountDetail, item); 47 } 48 49 //显示明细功能 50 void showDetails(struct MyAccount* myaccount) { 51 printf("%s", (*myaccount).accountDetail); 52 } 53 54 //退出功能 55 void myExit() { 56 do { 57 printf("确定退出?y/n:"); 58 scanf("%c", &isout); 59 getchar(); 60 if (isout == 'y' || isout == 'n') { 61 break; 62 } 63 } while (1); 64 if (isout == 'y') { 65 Loop = 0 ; 66 the printf ( " Exit program budgets " ); 67 } 68 } 69 70 71 is // menu printing 72 void printMenu ( struct MyAccount * myAccount) { 73 is do { 74 the printf ( " ---- --- family income and expenditure software ---- \ the n- " ); 75 printf ( " 1, income and expenditure details ---- \ the n- " ); 76 printf ( " 2, registration revenue ---- \ the n- " ) ; 77 the printf ( " . 3, registration expenses ---- \ n- " ); 78 the printf ( " . 4, exit ---- \ n- " ); 79 the printf ( " Please select (1-4): " ); 80 Scanf ( " % C " , & Key); 81 getchar (); // filtered carriage 82 Switch (Key) { 83 Case ' . 1 ' : 84 // the printf ( "detailed balance \ n-"); BREAK; 85 showDetails (myaccount); // printMeun ( ) passed in argument is & myaccount, so myaccount here is printMenu the parameter, i.e. & myaccount, no longer pass & myaccount 86 BREAK ; 87 Case ' 2 ' : 88 importRed (myaccount ); 89 BREAK ; 90 Case ' . 3 ' : 91 is outputRed (myAccount); 92 BREAK ; 93 Case ' . 4 ' : 94 myExit (); 95 } 96 } the while (Loop); 97 } 98 99 void main () { 100 struct MyAccount myAccount; 101 // Initialization 102 myaccount.leftMoney = 1000.0 ; 103 // char AccountDetail [3000] = "balance \ t balance amount \ t account balance \ t Description \ N0 .00 \ t0.00 \ T \ t1000.00 \ n-"; 104 // definition of the structure of this accountDetail is a constant and can not be reassigned, to copy it to assign values 105 Memset (myaccount.accountDetail, 3000 , 0 ); // first cleared 106 strcpy (myaccount.accountDetail, " balance \ t payments amount \ t account balance \ t Description \ n0.00 \ t0.00 \ t \ t1000.00 \ the n- " ); 107 printMenu(&myaccount); 108 }