01. /* 02. * Copyright (c) 2012, School of Computer Science, Yantai University 03. * All rights reserved. 04. * Author: Zhao guanzhe 05. * Completion Date: July 6, October 25, 2012. * version No.: v1.0 07. * input Description: interest calculator 08. * Problem description: Enter the deposit amount, select the term, and the day to get the expected interest 09. * program output: interest, interest 10. * Problem Analysis: Calculate the corresponding interest rate 11 based on the selected period. * Algorithm Design: Interest = Amount × annual interest rate × period 12. */# include <iostream >#include <cmath> using namespace std; int main () {double rate, money, time, B; int; cout <"welcome to the interest calculator! \ N "; cout <" Enter the deposit amount: "; cin> money; cout <"======= deposit term =====\ n"; cout <"1. demand deposits \ n "; cout <" 2.3 months \ n "; cout <" 3.6 months \ n "; cout <" 4.1 years \ n "; cout <"5.2 years \ n"; cout <"6.3 years \ n"; cout <"7.5 years \ n "; cout <"Enter the deposit term Code:"; cin> a; if (a <1 | a> 7) {cout <"You have an error! ";}Else {switch (a) {case 1: cout <" Enter the deposit days: "; cin> time; rate = 0.005 * money * (time/360); break; case 2: rate = 0.0310 * money * 0.25; break; case 3: rate = 0.033 * money * 0.5; break; case 4: rate = 0.035 * money; break; case 5: rate = 0.044 * money * 2; break; case 6: rate = 0.05 * money * 3; break; case 7: rate = 0.055 * money * 5; break;} B = money + rate; cout <"Expiration interest:" <rate <"RMB" <endl; cout <"total principal and interest:" <B <"Yuan" <endl; cout <"Thank you for your use. Welcome to the next time! "<Endl;} return 0 ;}
Running result:
Experience:
When I first saw this question, I thought it was too difficult and difficult. But after I completed the Personal Income Tax calculator, I suddenly realized that after the Code was completed, there was basically no error, but the interface is not perfect. Later, after the line feed, this program feels good. Previously, the code was too tedious to write and some irrelevant numbers were introduced. He said no. After debugging, I finally succeeded!
Knowledge Point summary:
The switch statement is learned, but the input statement is inserted into the statement. Each case expression is executed differently. Remember to add "break" after the case statement ".