Pre-Lab - Lab (4)



Answer the following questions in writing and collect the anwers in a text file called WarmUp.txt.
1) Write a C++ program segment that displays the amount of tax, based on the following tax table.  Assume that the income has already been entered from the keyboard.
 
 
More than
Less than or Equal to
%Tax
$ 0 $ 18,000 0
$ 18,000 $ 30,000 10
$ 30,000 $ 45,000 12.5
$ 45,000 $ 60, 000 15
$ 60,000 $ 80,000 17.5
$ 80,000 20

 

2) In C++ you can declare a variable at any point of the program.  Do you think the following code segment will result in a syntax error?  If not, what would be the output of the program?

int x = 12;
{
       int x = 3;
       cout << "1st " << x << endl;
}
cout << "2nd " << x << endl;
 
 

3) Suppose you have a while loop that executes many times, but you want to exit the loop if a certain condition occurs.  How do you get out of a loop before the maximum number of loops is reached.