Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8861431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:29:28+00:00 2026-06-14T15:29:28+00:00

I wrote a certain method on how to access my fields in a class

  • 0

I wrote a certain method on how to access my fields in a class, but my teacher told me I should use an enum.

How can I re-write this code to use an enum and not use gotos?

void SetType() {
    cout << "Book SetType" << endl;
    Choice: cout << "Please Select from the list: \n "
            << "1- Technical literature \n "
            << "2- Fiction literature \n "
            << "3- Textbook" << endl;
    int i;
    cin >> i;

    switch (i) {
    case 1:
        Type = "Technical literature";
        break;
    case 2:
        Type = "Fiction literature";
        break;
    case 3:
        Type = "Textbook";
        break;
    default:
        cout << "Erorr you entered a wrong choice" << endl;
        goto Choice;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:29:29+00:00Added an answer on June 14, 2026 at 3:29 pm

    just use loops instead of gotos of it is going to be a spaghetti code.
    Enums are fine to does not care about the numbers for the defines, because they are incremented automatically if you add a new one.

    #include <iostream>
    #include <string>
    void SetType();
    
    using namespace std;
    string Type;
    int main()
    {
        SetType();
    
        cout << "so you choose " << Type << endl;
        return 0;
    }
    enum select
    {
        Technical_literature = 1,
        Fiction_literature,
        Textbook
    };
    
    void SetType() {
        cout<<"Book SetType"<<endl;
        while(1)
        {
            cout<<"Please Select from the list: \n 1- Technical literature \n 2- Fiction literature \n 3- Textbook"<<endl;
            int i;
            cin >> i;
    
            switch(i) {
            case Technical_literature:
                Type="Technical literature";
                return;
            case Fiction_literature:
                Type="Fiction literature";
                return;
            case Textbook:
                Type="Textbook";
                return;
            default:
                cout << "Erorr you entered a wrong choice" << endl;
    
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote the class Link which has a method shortTolong() this should return the
I wrote extension method to Timer class to destroy it after certain amount of
I am trying to write a detector that checks if a certain directory can
Case i'm trying to write a GWTTestCase for a certain class, used as a
I'm pretty certain I'm missing something really obvious here but this seems quite bizarre.
How can I make sure that a certain instance of a class will never
The CopyTo method of FileInfo class throws an IOException The process cannot access the
Suppose someone wrote a method that opens a certain file and forgets to close
I wrote a user script that performs a certain operation on selected text in
I wrote a custom URL rewriting module, to take certain paths and map them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.