Sample Source Code For Switch Statement
Sample Source Code For Switch Statement
int main()
{
char choice;
switch (choice)
{
case 'A': cout << "You entered A.\n";
break;
case 'B': cout << "You entered B.\n";
break;
case 'C': cout << "You entered C.\n";
break;
default: cout << "You did not enter A, B, or C!\n";
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
char choice;
int main()
{
int modelNum;
switch (modelNum)
{
case 300: cout << " Picture-in-a-picture\n";
case 200: cout << " Stereo sound\n";
case 100: cout << " Remote control\n";
break;
default : cout << "You can only choose the 100, 200, or 300.\n ";
}
return 0;
}
// The switch statement in this program uses the "fall through" feature
// to catch both uppercase and lowercase letters entered by the user.
#include <iostream>
using namespace std;
int main()
{
char feedGrade;
int main()
{
int num = 4; // num starts out with 4
int main()
{
int number = 1;
while (number <= 5)
{
cout << "Hello ";
number++;
}
cout << "\nThat's all!\n";
return 0;
}
int main()
{ int num = 1;
int main()
{
int num, // Counter telling what number to square
lastNum; // The final integer value to be squared
int main()
{
int score1, score2, score3; // Three test scores
double average; // Average test score
char again; // Loop again? Y or N
do
{ // Get three test scores
cout << "\nEnter 3 scores and I will average them: ";
cin >> score1 >> score2 >> score3;
int main()
{
int numDays; // Number of days
double dailySales, // The sales amount for a single day
totalSales = 0.0, // Accumulator, initialized with 0
averageSales; // The average daily sales amount