Phone Balance Simulation Program

Source: Internet
Author: User

Note:

In fact, this program is very simple. It only uses some basic syntax knowledge and simple logical relationships. Next I will explain the functions implemented by this program.

1. The program reads the account balance of each user from the specified file and saves it in the array of user;

2. manually enter the time when the user calls the phone. The default value is 1 RMB per minute;

3. The program displays the I-th user account balance and determines whether to continue calling.

Code:

 1 // &author: Stone 2 // time: 2013/5/16 3 #include <stdio.h> 4 #define MAX 10 // Define the max users 5  6 int main () 7 { 8     int user[MAX]; // define users to int 9     FILE* fp; // define file10     fp = fopen("user information.txt", "r"); // open file11     int i;12     for (i = 0; i < MAX; ++i)13     {14         fscanf(fp, "%d", &user[i]); // input data from the file15     }16 17     while (1)18     {19         printf("Please enter how long did it take to which user.\nFORMAT:2 12min\n");20         int user_i, time;21         scanf("%d %dmin", &user_i, &time);22         if (!user_i) // Exit criteria23         {24             break;25         }26 27         if (user[user_i - 1] == 0) // overdue bills28         {29             printf("Sorry, you have no current available balance of account.\nAnd can continue to use after prepaid phone.\n\n");30         }31         else if (user[user_i - 1] < 0) // overdue bills32         {33             int own = 0 - user[user_i - 1];34             printf("Sorry, your account is now overdue bills of ¥%d.\nAnd can continue to use after prepaid phone.\n\n", own);35         }36         else37         {38             user[user_i - 1] -= time; // The ith user to computing time39             if (user[user_i - 1] >= 0) // no overdue bills40                 printf("User %d remaining %d minutes.\n\n", user_i, user[user_i - 1]);41             else // overdue bills42                 printf("I'm sorry, you have overdue bills.\n\n");43         }44     }45 46     fclose(fp); // close file47     return 0;48 }

User information.txt

100
100
100
100
100
100
100
100
100
100

Because it is a bit of self-thinking, it is divided into the "New Thinking" category...

 

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.