|
|
Decision MakingHow does a program direct the computer or instructs the computer to follow certain path?C is a procedural language, which means that program progresses sequentially and depends on prior values. The decisions are made as the program proceeds. How does the computer decide? By comparing. The computer checks for a given condition, if the condition is met the program progress along certain direction. There is always one condition and only one condition for a procedural program to flow until the end. But, I know that my desktop computer can perform many things such as play music, surf net, and receive input at the same time. How do you explain that? Of course. Modern computers have more than one processor, and even a computer with one processor can employ multiprocessing techniques to give an impression of many things going on at the same time. The extremely speedy calculation or operation of the computer makes the sequential nature of execution of computers illusionary. How exactly do we make a decision in programming? In general, if, else if, else are the basic format for making a decision. Consider the example below. /* Project: Lab3 */ /* File: decide.C */ /* Aim: Learn decision making */ /* Keywords: if, switche */ #include
|