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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:17:12+00:00 2026-05-21T02:17:12+00:00

This is what I have to do: A teacher has asked all her students

  • 0

This is what I have to do:

A teacher has asked all her students to line up single file according to their first name. For example, in one class Amy will be at the front of the line and Yolanda will be at the end. Write a program that prompts the user to enter the number of students in the class, then loops to read in that many names. Once all the names have been read in it reports which student wourld be at the front of the line and which one would be at the end of the line. You may assume that no two students have the same name. Input Validation: Do not accept a number less than 1 or greater than 25 for the number of students.

This is what I have so far:

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main()
{
    int StudentNum;

    cout << "How many student are in the class?\n";
    cin >> StudentNum;

    char sname[StudentNum + 1][25];
    if (StudentNum < 1 || StudentNum > 25)
    {
    cout << "Please enter a number between 1-25 and try again\n"; 
    return 0;
    }

    for (int i = 1; i <= StudentNum; i++); 
    {
        cout << "Please enter the name of student #" << i << endl;
        cin >> sname[i];        
    }   
    for (int output = 0; output <=StudentNum; output++);
    {
    cout << endl << sname[output] << endl;
    } 
    system ("pause");
    return 0;
}

Am I missing something about arrays??

  • 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-21T02:17:12+00:00Added an answer on May 21, 2026 at 2:17 am

    You cannot create such an array because its length has to be known at compile time (i.e., it cannot be the result of an expression such as StudentNum + 1).

    You can solve this issue because by the problem definition you know an upper bound for the array size, so you can use that as a compile time constant.

    However, this problem can be solved without using an array at all. Read the wording carefully.

    Hint for the solution without arrays: Think of the array as a single piece of paper (variable) with all the names written one after another. Not using an array then means that you have to be able to solve the problem without looking at all the names at once. How would you come to the answer if I only allowed you to see the names one by one?

    Another hint: The problem is still solvable if there were several trillion students in the class (with unique names no less), i.e. more than could possibly fit in the computer’s memory at any one time.

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

Sidebar

Related Questions

So the teacher has posed this assignment: You have been hired by the United
I have an assignment that my teacher has told us to use this in
Has anyone done this / have some example code?
Running ipconfig /all shows a Teredo Tunneling Pseudo-Interface. What is that? Does this have
I have this line in a javascript block in a page: res = foo('<%=
I have a teacher model which has_many students. When I render a student (as
I have a table called Item which has an ID, a Name and a
Say we have two entities:teacher and student. each teacher has multiple student. Now I
I have this homework question: Assume a Database table has 0 records at time
I have this site I am working on, it has the following menu items:

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.