Exercise of If-Then-Else Statment:
- Get a copy of the
This program demonstrates how to use if-else statement.
- Entering the cp command in hercules:
cp /net/data/ftp/pub/class/110/ftp/cpp/if/convert.cpp convert.cpp
- or, using your mouse to copy and paste the program into Nano text editor or Visual C++.
- Test the program with these inputs:
- Explain to yourself:
- Why do the last three sets of the input values yield the same output?
- Why isn't c the same as C?
- Why would you type any number after d even though d is not a known conversion type?
- You should use two if-else structures to fix the program:
- One will validate the letter as soon as it is typed:
If the input letter is not C, c, F , or f, output "wrong letter".
then use an else to skip the rest of the program (do not ask for temperature, do not print result)
Do not return early.
- The other will choose what conversion to use.
Make sure to treat (C 100) and (c 100) the same,
and treat (F 32) and (f 32) the same;
- Use the same test as before and show the results to your lab instructor.
Copyright: Department of Computer Science, University of Regina.