C language: Code "programming and development" for the red packet snatching program and development for the red packet snatching Program

Source: Internet
Author: User

C language: Code "programming and development" for the red packet snatching program and development for the red packet snatching Program

In fact, this is a fairly simple piece of code. As for why I want to put it on my blog, it is mainly for those who are new to programming (or those who are interested in programming ), A relatively intuitive program (mini game) may be more interesting to them, or more enthusiastic about programming. First of all, I also came from that stage. I am confused about the teacher's knowledge in class. I am not familiar with some operators, statements, and structures. How can I use them, as a result, I found several examples of hands to practice, and gradually learned the knowledge of the teacher during the practice. I am more interested in programming. Next we will give you a lite version of the red packet snatching program. Run it on your own.

#include
 
  #include
  
   #include
   
    #include
     
    
   
  
 
This is the header file of the program. I don't think we should know it as much as I can say;
Int hongbao () {int num = 100; float total = 100; float a [101]; float min = 0.01; int I; float t; float safe_total = 0; float sum = 0; srand (time (0); for (I = 1; I
 
  
This is the whole program for snatching red packets. I define it as a function to make the game more interesting (you can set a loop by calling the main function ). In the code segment, I set a default value of 100 yuan and 100 red packets, and then grab them by myself. The amount of each red packet is allocated randomly. Here, a one-dimensional array is used for storage; these statements are output through traversal.
  
Int main () {loop1: hongbao (); printf ("\ n"); while (1) {printf ("continue to grab red packets (Y \ N) \ n "); int a; scanf (" % c ", & a); getchar (); a = toupper (a); if (a = 'y ') {goto loop1;} elseif (a = 'n') {printf ("Congratulation !!! "); Break;} else {printf (" your input is wrong! Please input again \ n "); continue ;}} return0 ;}

  

The main function is very easy to understand. It is to call the hongbao () function. As for the while LOOP, we mentioned above that we only have to choose whether to continue when testing the game. Others are some print statements, which are easy to understand. Here, the goto statement is used for convenience, because the loop of this program is not complex, and this operation is done in a simple and intuitive way. (To be honest, this is my code a long time ago)

Paste the entire code.

# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
       
Int hongbao () {int num = 100; float total = 100; float a [101]; float min = 0.01; int I; float t; float safe_total = 0; float sum = 0; srand (time (0); for (I = 1; I
       
        
The above is a lite version of the red packet snatching code, hoping to help you.
        

In fact, programming is a very interesting thing. You can add something and improve it based on a simple piece of code. In this process, you will make progress slowly, as the saying goes, starting from a trivial matter, over time, you will find yourself doing a great job. Share today, express your thoughts only based on your personal interests, and wish you and me to learn and make progress together.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.