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 6572817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:03:15+00:00 2026-05-25T15:03:15+00:00

First, this is for my CS296 class, so everything has to be in the

  • 0

First, this is for my CS296 class, so everything has to be in the main() function and I can’t use anything but loops, switch, and if statements.

Anyway, the program ask the user to enter the number of students in a class, followed by their names. It then displays which student should be at the front of the line and which student should be at the back of the line based on the students being lined up alphabetically from A-Z.

The program runs, but I feel like the design is poor. Specifically with how I’m using the count variable. I was hoping maybe to get some feedback regarding that. Thanks!

int main(void)
{
    string front, back, student;
    unsigned short count = 1, students;

    cout << "Enter the number of students in the class. Valid range is 1 - 25." << endl
         << endl
         << "Students: ";
    cin  >> students;

    while (students < 1 || students > 25)
    {
        cout << endl
             << "ERROR: Valid range is 1 - 25" << endl
             << endl
             << "Students: ";
        cin  >> students;
    }

    cout << endl
         << "Enter the name of student " << count << ": ";
    cin.ignore();
    getline(cin, student);

    front = back = student;

    for (count = 2; count <= students; count++)
    {
        cout << "Enter the name of student " << count << ": ";
        getline(cin, student);

        if (student < front)
            front = student;
        else if (student > back)
            back = student;
    }

    cout << endl
         << front << " should be at the head of the line." << endl
         << back  << " should be at the end of the line."  << endl;

    return 0;
}
  • 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-05-25T15:03:16+00:00Added an answer on May 25, 2026 at 3:03 pm

    No, that seems fine. Specs called for entering a count and then entering that many students which is exactly what you’ve done.

    Don’t get me wrong, the program is bad but that’s because of ridiculous specs like “everything has to be in the main() function”, not anything to do with your implementation.

    For this level of homework, I’d be happy getting something like that from my students. It would make a nice change from code that doesn’t even compile, single-character variable names everywhere, or an unformatted morass of incorrect indentation and mixed tabs/spaces 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code first: '''this is main structure of my program''' from twisted.web import http from
problem euler #5 i found the solution but i don't know why this first
Using Dozer to map two objects, I have: /** /* This first class uses
#include <iostream> using namespace std; // This first class contains a vector and a
First check out this code. I seems like it should work for me, but
first of all: this is not the same as this . The ModelBackend has
First: This is not a repeat of this question . Same script, but different
something like public static class StringHelpers { public static char first(this string p1) {
$(SomeInputField).keydown(function () { $(SomeDiv).css(top, 30px); }); First this is making a div go 30px
OK,First this program can load plist from URL by this code,and I put this

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.