void visual_init(t_general *gen) { if (!gen->visual) return ; start_graph(); gen->map = newwin(65, 193, 2, 4); gen->text = newwin(1, 1, 67, 256); gen->board = newwin(64, 52, 2, 200); refresh(); pc_color_up(gen); map_display(gen, 0, 1); initial_info(gen); wrefresh(gen->map); wrefresh(gen->board); }
int main (int argc, char *argv[]) { // Business loan int loan_num; float rate = BUSINESS_LOAN_RATE / 12; // 5.4% / 12, month rate int i = 0; float fee = 0; float fact = 0; float total_fee = 0; float total_bj = 0; float bj = 0; float bx_fee = 0; float bx_loan_num = 0; float bx_total_fee = 0; float bx_monthly = 0; // House Fund loan int house_fund_num = HOUSE_FUND_NUM; // 120w float house_fund_rate = HOUSE_FUND_RATE / 12; // month rate float house_fund_fee = 0; float house_fund_fact = 0; float house_fund_total_bj = 0; float house_fund_bj = 0; int bx_house_fund_num = HOUSE_FUND_NUM; // 120w float bx_house_fund_fee = 0; float bx_house_fund_monthly = 0; // savings = bj - bx float savings = 0; float total_savings = 0; float bx_benefit = 0; float tmp = 0; float max_bx_benefit = 0; // Investment int invest_num = 0; float invest_rate = INVEST_RATE / 12; float income = 0, total_income = 0, year_income = 0; initial_info (); print_info (); loan_num = bx_loan_num = max_loan; fact = loan_num / max_loan_month; invest_num = remain_num; house_fund_fact = house_fund_num / max_loan_month; bx_monthly = (bx_loan_num * rate * pow(1+rate, max_loan_month)) / (pow(1+rate, max_loan_month) - 1); printf("Business Loan, monthly pay = %d, bx monthly pay = %f\n", fact, bx_monthly); for (i = 0; i < max_loan_month; i++) { fee = loan_num * rate; loan_num -= fact; total_fee += fee; bx_fee = bx_loan_num * rate; bx_loan_num -= (bx_monthly - bx_fee); if (bx_loan_num < 0) bx_loan_num = 0; bx_total_fee += bx_fee; if (!(i % 12)) printf("\n\n---------------- YEAR %d --------------\n", i/12 + 1); printf("Month %03d, fee %05f, monthly %05f, bx_load_num = %f, bx_fee %05f, bx_monthly %05f\n", i+1, fee, fee + fact, bx_loan_num, bx_fee, bx_monthly); if ((i %12) == 11) printf("Total fee = %f, bx total fee = %f\n", total_fee, bx_total_fee); } printf("\n\nHouse Fund + Business Loan\n"); total_fee = bx_total_fee = 0; bx_loan_num = loan_num = business_loan; bx_monthly = (bx_loan_num * rate * pow(1+rate, max_loan_month)) / (pow(1+rate, max_loan_month) - 1); bx_house_fund_monthly = (bx_house_fund_num * house_fund_rate * pow(1+house_fund_rate, max_loan_month)) / (pow(1+house_fund_rate, max_loan_month) - 1); fact = loan_num / max_loan_month; for (i = 0; i < max_loan_month; i++) { house_fund_fee = house_fund_num * house_fund_rate; house_fund_num -= house_fund_fact; total_fee += house_fund_fee; bx_house_fund_fee = bx_house_fund_num * house_fund_rate; house_fund_bj = (bx_house_fund_monthly - bx_house_fund_fee); house_fund_total_bj += house_fund_bj; bx_house_fund_num -= house_fund_bj; bx_total_fee += bx_house_fund_fee; fee = loan_num * rate; loan_num -= fact; total_fee += fee; bx_fee = bx_loan_num * rate; bj = (bx_monthly - fee); bx_loan_num -= bj; total_bj += bj; bx_total_fee += bx_fee; savings += fee + house_fund_fee + house_fund_fact + fact - bx_monthly - bx_house_fund_monthly; if (savings <= 0) savings = 0; if (!(i % 12)) printf("\n\n---------------- YEAR %d --------------\n", i/12 + 1); printf("Month %03d, house_fund_fee %05f, fee %05f, monthly %05f, bx_house_fund_fee %f, bx_fee %f, bx_monthly %f\n", \ i+1, house_fund_fee, fee, fee + house_fund_fee + house_fund_fact + fact,\ bx_house_fund_fee, house_fund_fee, bx_monthly + bx_house_fund_monthly); if ((i % 12) == 11) { total_savings += savings; bx_benefit = total_savings - (bx_total_fee - total_fee); if (bx_benefit > max_bx_benefit) max_bx_benefit = bx_benefit; printf("Total fee = %f, bx total fee %f, savings in this year %f, total_savings %f\n", total_fee, bx_total_fee, savings, total_savings); printf("bj spend house_fund benjin = %f, bj spend benjin %f, tatal %f\n", (i+1)*house_fund_fact, (i+1)*fact, (i+1)*(house_fund_fact+fact)); printf("bx spend house_fund benjin = %f, bx spend benjin %f, total %f\n", house_fund_total_bj, total_bj, house_fund_total_bj+total_bj); printf("bx_benefit = %f, max_bx_benefit %f\n", bx_benefit, max_bx_benefit); savings = 0; } } printf("\n\nInvest income %d\n", invest_num); for (i = 0; i < max_loan_month; i++) { income = invest_num * invest_rate; year_income += income; if (!(i % 12)) printf("\n\n---------------- YEAR %d --------------\n", i/12 + 1); printf("Month %03d, income %05f\n", i+1, income); if ((i %12) == 11) { printf("year income = %f\n", year_income); total_income += year_income; printf("Total income = %f\n", total_income); invest_num += year_income; year_income = 0; } } return 0; }
int main(int argc, char **argv) { int op; struct server_info s_info; char *path; char *address; char *file; char *port; /* default 8080 */ char *root; int exit_code = 0; int i = 0; int test_digit = 1; setprogname(argv[0]); s_info = initial_info(s_info); while ((op = getopt(argc, argv, "dhc:i:l:p:")) != -1) { switch (op) { case 'd': s_info.debug_mode = 1; break; case 'h': /* print usage and exit */ usage(0); break; case 'c': path = optarg; s_info.cgi_dir = path; break; case 'i': s_info.all_ip = 0; address = optarg; s_info.address = address; break; case 'l': file = optarg; s_info.logging_file = file; break; case 'p': port = optarg; for (i = 0; i < strlen(port); i++){ isdigit(port[i]) > 0 ? (test_digit &= 1) : (test_digit &= 0); } if (test_digit) s_info.port = atoi(port); else{ fprintf(stderr, "port format error:%s\n", port); exit(EXIT_FAILURE); } if (atoi(port) > 65535 || atoi(port) < 0){ fprintf(stderr, "port:%s overranged\n", port); exit(EXIT_FAILURE); } break; case '?': usage(1); break; case ':': usage(2); break; default: usage(3); break; } } argc -= optind; argv += optind; root = argv[0]; if (argc) s_info.server_root = root; else { printf("please set root dir for server\n"); usage(4); return 1; } exit_code = set_server(&s_info); return exit_code; }