C language preliminary study: branch structure experience (Pay), branch salary
Task and code:
/** Copyright (c) 2017 CSDN Emy * All rights reserved * file name: main. c * Author: Osseyda completion date: 2017.9.10 * version: v2. ** Problem description: similar to taxi pricing * problem output: a qualified solution is obtained. */# Include
# Include
# Define LimitHour 40 # define P1 20 # define P2 30int main () {int h, s; printf ("Enter the working time:"); scanf ("% d ", & h); if (h <= LimitHour) s = P1 * h; else s = P1 * LimitHour + P2 * (h-LimitHour); printf ("weekly salary: % d \ n ", s); return 0 ;}
Running result:
Knowledge Point summary:
1. Description of the problem; 2. if-else statement; 3. Use macro definition to replace constants (improving readability and making modifications easier)
TIPS:
At the beginning, I thought it was very simple. It was like a big bang!