Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create pseudocode and C++ code for a program that accepts a number representing

ID: 3813981 • Letter: C

Question

Create pseudocode and C++ code for a program that accepts a number representing a class and then displays the name of the class. Your program should continue to prompt for a class number and display the name of the class until a sentinel value is entered. You decide what value will be used as the sentinel.

Im trying to implement the sentinal to make it quit but not sure how to go about it. This is what I have so far.

#include <iostream>

using namespace std;

int main()
{
int classNo;
do{

cout << " Enter Class Number 1 to 5 (-1 to quit): " << endl;
cin >> classNo;

if(classNo == 1 )
cout<<" Smart Alec 101";
else if(classNo == 2)
cout<<" Napping 205";
else if (classNo == 3)
cout<<" Yogi Bear Yoga 110";
else if (classNo == 4)
cout<<" Yogi Berra Yoga 108";
else if(classNo == 5)
cout<<" Moshing 330";
else {
cout<<" You have entered wrong value"<<endl;
cout<<"Please enter the class id between 1 and 5"<<endl;
}
}while(1 == 1);
  
return 0;
}

Class Number Class Name 1 Smart Aleck 205 2 Napping 205 3 Yogi Bear Yoga 110 4 Yogi Berra Yoga 108 5 Smashing 330

Explanation / Answer

HI

I have modified the code and highlighted the code changes below

#include <iostream>
using namespace std;
int main()
{
int classNo;
do{
cout << " Enter Class Number 1 to 5 (-1 to quit): " << endl;
cin >> classNo;
if(classNo == 1 )
cout<<" Smart Alec 101";
else if(classNo == 2)
cout<<" Napping 205";
else if (classNo == 3)
cout<<" Yogi Bear Yoga 110";
else if (classNo == 4)
cout<<" Yogi Berra Yoga 108";
else if(classNo == 5)
cout<<" Moshing 330";
else if(classNo != -1){
cout<<" You have entered wrong value"<<endl;
cout<<"Please enter the class id between 1 and 5"<<endl;
}
}while(classNo != -1);
  
return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                     

sh-4.2$ main                                                                                                                  

                                                                                                                              

Enter Class Number 1 to 5 (-1 to quit):                                                                                       

1                                                                                                                             

                                                                                                                              

Smart Alec 101                                                                                                                

Enter Class Number 1 to 5 (-1 to quit):                                                                                       

2                                                                                                                             

                                                                                                                              

Napping 205                                                                                                                   

Enter Class Number 1 to 5 (-1 to quit):                                                                                       

-1

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote