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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:18:09+00:00 2026-06-14T11:18:09+00:00

I want to make a vector of doubles from user input. These lines of

  • 0

I want to make a vector of doubles from user input. These lines of code do generally what I want them to do, except for two cases, and if there are more please let me know. The two cases are if there are two or more decimal places, and if there is one or more spaces. The second decimal acts as a space. So if the user inputs this: 0.2.0.1, or 0.2 0.1, I would get two decimals for both instances and they would be 0.2 and 0.1. Please help me on this. I want to make sure I am doing this simple task correctly. I am doing this in C++.

Any other suggestions are more than welcome.

for(int i = 0; i <= ARRSIZE; i++)
{
    cout << "Please enter a decimal value: ";
    if (cin >> sumScores)
    {
        scoresVector.push_back(sumScores);
        cin.clear(); 
        cin.ignore();
    }else
    {
        cout << "This is not a double\n";
        scoresVector.push_back(0);
        cin.clear(); 
        cin.ignore();
        cin.ignore(numeric_limits<streamsize>::max(), '\n'); 
    }
}
  • 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-14T11:18:10+00:00Added an answer on June 14, 2026 at 11:18 am

    There are better solutions to handle linewise inputs, but they all require some additional code. The easiest way is reading a line using std::getline and analyze them with a stringstream.

    for (int i = 0; i <= ARRSIZE; i++) {
      std::cout << "Please enter a decimal value: " << std::flush;
      std::string s;
      if (!std::getline(std::cin, s))
        break;
    
      std::istringstream is(s);
      double d;
      if (is >> d >> std::skipws && is.eof()) {
        scoresVector.push_back(d);
      } else {
        std::cout << "This is not a double\n";
        scoresVector.push_back(0);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I want to validate my input, should I make validation code as private
I have a decimal variable x0. I want to make a vector from [x0,
I have an R question--I want to make a vector of functions, and then
I want make a bash script which returns the position of an element from
I want make interactive application where user launches it and can do various task
I want to make a global vector of my own object class called Person.
I want to make a static vector in a class and I want to
I want to make vertices an array of Vector . But I don't know
I want make datetimepicker in my project. Using jquery how it is possible? I
Let's say I want make some of my sources publicly available via my blog

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.