当前位置:网站首页>Small project - household income and expenditure software (1)

Small project - household income and expenditure software (1)

2022-06-13 05:05:00 Jason_ LH1024

Simple and miscellaneous code :

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
  char key=' ';
  int loop = 1;
  char details[3000]="------------ Current revenue and expenditure details record -----------\n Income and expenditure \t Amount of revenue and expenditure \t Amount of account \t say   bright \n";
  char note[20]="";// A statement of income or indication 
  char temp[100]="";// Used to format the income or expenditure each time , Then splice it to details 
  double money = 0.0;
  double balance = 1000.0; // Account balance , Initial value  
  char choice =' ';// Determine whether to exit y/n 
  int flag = 0; // Determine whether there are details  
  
  do{
	  printf("\n-------- Family income and expenditure accounting software ----------");
	  printf("\n        1  Income and expenditure details ");
	  printf("\n        2  Registered income ");
	  printf("\n        3  Register expenses ");
	  printf("\n        4  refund      Out ");
	  printf("\n Please select (1-4):");
	  scanf("%c",&key);
	  getchar();// Filter return 

	  switch(key){
	  case'1':
	  	if(flag){
		  
		  printf("%s",details);
	}else{
		printf(" There are currently no details , Please do me a favor !");
	}
		  break;
	
	  case'2':
		  printf("\n The amount of income this time :");
		  scanf("%lf",&money);
		  getchar(); // Filter return 
		  
		  balance+=money; // Update amount 
		  
		  printf("\n This income statement :");
		  scanf("%s",note);
		  getchar();
		  
		  sprintf(temp,"\n income \t%.2f\t\t%.2f\t\t\t%s",money,balance,note);// Send this information , Write to temp character 
		 // Joining together to details
		 strcat(details,temp); 
		 flag = 1; 
		  break;
	  case'3':
		  printf("\n The amount of this expenditure is :");
		  scanf("%lf",&money);
		  getchar(); // Filter return 
		  if(money>=balance){
		  	printf(" Lack of balance !");
	}else {
	
		  balance-=money; // Update amount 

		  printf("\n This expenditure statement :");
		  scanf("%s",note);
		  getchar();
		  
		  sprintf(temp,"\n spending \t%.2f\t\t%.2f\t\t\t%s",money,balance,note);// Send this information , Write to temp character 
		 // Joining together to details
		 strcat(details,temp); 
		 flag = 1;
	}
		  break;
	  case'4':
		  printf("\n Are you sure you want to quit ?y/n:");
		  do{
		  	
		  	scanf("%c",&choice);
		  	getchar();
		  	if(choice=='y'||choice=='n'){
                   	break;	  		
			  }
			  	printf("\n Your input is wrong , Please re-enter y/n:");
		  } while(1);
		  if(choice=='y'){
		  
	      loop = 0;
            }
}
	  }while(loop);
	  printf(" You have exited the software !");
	  getchar();
}
	  
  

 

原网站

版权声明
本文为[Jason_ LH1024]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280515587242.html