// Console_Using_Switch.cpp : main project file. /* ________________________________________________ Learning C++: Lesson 4 Making Decisions With Switch Ron Kessler Created 5/22/2016 This little program shows how to use Switch instead of if statements to make decisions. Users enter a State and we return the sales tax rate _________________________________________________ */ #include "stdafx.h" using namespace System; using namespace Text; int main(array ^args) { //---show a message Console::WriteLine("Welcome to the Sales Tax Police\n\n"); //---get a number Console::WriteLine("Please enter a state code: CA = 1, AZ = 2, NV = 3, or WA = 4....\n"); int stateCode = 0; int choice = int::TryParse(Console::ReadLine(), stateCode); //---evaluate it here. MUST be an int or char to use Mr. Switch! Show how to use a break point. F9 & F11 double taxRate = 0; switch (stateCode) { case 1: taxRate = 8; break; case 2: taxRate = 6.75; break; case 3: taxRate = 4.5; break; case 4: taxRate = 3.5; break; default: taxRate = 0; break; } if(taxRate > 0) Console::WriteLine("The tax rate in your state is " + taxRate + " % which is too much!\n\n"); else Console::WriteLine("You did not make a choice. I am sending out the cops.\n\n\n"); Console::WriteLine("Press any key to end."); Console::ReadLine(); //keeps the window/console open }