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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:45:07+00:00 2026-06-16T21:45:07+00:00

After writing some pretty terse C++ using the sub script operator, I have a

  • 0

After writing some pretty terse C++ using the sub script operator, I have a small error in the program – there’s no output.

I input this (Linux)

54 73 89 43 38 90

in then hit Cntrl + D for EOF. The program outputs nothing and stops executing.

Source:

#include <iostream>
#include <string>
#include <vector>

using std::cin;
using std::vector;
using std::cout;
using std::endl;

int main() {
vector<unsigned> scores(11, 0); //11 buckets, all initially 0
unsigned grade;
while(cin >> grade) //read the grades
{
   if(grade <=100) //handles only valid inputs
  {
   ++scores[grade/10]; //increment counter for the current cluster
  }
 }
}

I haven’t changed my settings in VIM so the coding style is slightly off. I cannot conceive what is wrong, the while loop is pretty standard. It reads into grades until it find the stream is not valid. I then check the input for being less than 100 (inclusive). The final piece of code (it’s pretty terse) find the correct element in the vector to increment the counter.

I have a feeling it could perhaps be my input that’s causing the program to not output.

EDIT 1: I added the output statement, I did this by using dereferencing a which is always a reference.

#include <iostream>
#include <string>
#include <vector>

using std::cin;
using std::vector;
using std::cout;
using std::endl;

int main() {
vector<unsigned> scores(11, 0); //11 buckets, all initially 0
unsigned grade;
while(cin >> grade) //read the grades
{
   if(grade <=100) //handles only valid inputs
  {
   ++scores[grade/10]; //increment counter for the current cluster
  }
 }
for(auto it = scores.begin(); it != scores.end(); ++it) {
cout << *it << endl;
 }
}
  • 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-16T21:45:08+00:00Added an answer on June 16, 2026 at 9:45 pm

    I have a feeling it could perhaps be my input that’s causing the program to not output.

    Not quite. It’s the absence of output statements in your program that’s causing it to not output.

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

Sidebar

Related Questions

I have a file which I write some java objects. After writing, sometimes I
I am currently writing a paper on the Android platform. After some research ,
Suppose, I have a connected socket after writing this code.. if ((sd = accept(socket_d,
I am using JQuery to execute an operation within a web service. After writing
I'm writing a tic tac toe program that plays throuh the terminal/console After Player
I'm writing a physics simulating program, and found after() useful. I once would like
Been writing some raw SQL queries after noticing how inefficient some of Django's built-in
I was writing some php code after a long sint doing ruby and I
I'm having some trouble with a jquery script I'm writing, as I cannot get
i have a small problem with writing my application.. I have custom dialog what

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.