You are here:

C++/C++ Programming and Problem Solving


   I need some help with writing a program with a switch statement. I have to call the gas pump
with regular, mid grade, and preimum with diesel as my default. I'm not sure if I made that clear but I'm confused I have a little code if that would help. I hope you can help me if not thank you for your time. I'm using a C++ Compiler.  

#include <iostream.h>

Fuel Type();

int main()
  cout << Your fuel type(regular, plus, super, preimum)."<<endl;    

for (i=1;i<=5; i++)
Fuel Type
case'87':  cout << "regular";

case'89':  cout << "plus";

case'93':  cout << "super";
default:   cout << fuel << " is premium fuel  

Dejuan , Thank you for your question.

A switch statement works like this:

long FuelType; // Declare a variable
FuelType = 89; // Set it to a value

// Print out the fuel grade corresponding to the
// value 89

switch (FuelType)
case 87: cout << "regular";

case 89: cout << "plus";

case 93: cout << "super";

default: cout << "unknown grade";
} // End of the switch statement

The switch statement examines the value of the variable FuelType
and selects the case "89", which prints out "plus".

David Spector


All Answers

Answers by Expert:

Ask Experts


David Spector


Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.


I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2017 All rights reserved.

[an error occurred while processing this directive]