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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:47:00+00:00 2026-06-05T15:47:00+00:00

I am trying a coding Q and am looking for a line of code

  • 0

I am trying a coding Q and am looking for a line of code that detects if there was no input given (user just presses enter). The concerned datatype is int.

I’ve read few other Qs about this very problem, but didn’t fit in well with my needs. I have tried eof & other such suggestions to no avail…

Here’s the code –

#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
int main() {
int ogv,cgv=0,i,j=0,k;
int arr [3];
vector<int> ans;
while(true) {
    cgv=0;
    cin>>ogv;
    //if("ogv is not a number, just an enter") 
          break;
    arr[0]=floor(ogv/4);
    arr[1]=floor(ogv/3);
    arr[2]=floor(ogv/2);
    for(i=0;i<=2;i++) {
        if (arr[i]<0)
            arr[i]=0;
        cgv+=arr[i];
    }

    if(ogv>cgv) {
        ans.push_back(ogv);
    }
    else {
        ans.push_back(cgv);
    }
   j++;
}
for(k=0;k<j;k++) {
    cout<<ans.at(k)<<endl;
}
}

Your help is greatly appreciated…! 😀

Thanks

  • 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-05T15:47:01+00:00Added an answer on June 5, 2026 at 3:47 pm

    You can use the noskipws manipulator

    Example:

    int x = -1;
    cin>>noskipws>>x;
    if(x==-1)
    {
        // no number was entered, the user just pressed enter
    }
    else
    {
        // the user entered a number
    }
    

    EDIT: In order to use this in a loop, you need to discard the characters that are currently in the buffer before each read attempt.

    For example, if the user inputs the number 4 and presses enter in the first iteration of the loop, cin will read the 4, but it will leave the end-of-line character in the buffer. When the read occurs in the second iteration, cin will see the end-of-line character in the buffer and it will treat it as if the user pressed enter, exiting the loop.

    We can use the sync() method in order to discard any unread characters in the buffer. We need to do this before any attempt to read from cin:

    cin.sync();
    cin >> noskipws >> x;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to improve my coding style and I understand that my coding
I'm looking for a bit of brainstorming assistance. I am coding a layout that
I just finished coding a C# project targeting .Net v4. I'm trying to put
I'm trying to do something common enough: Parse user input in a shell script.
I'm trying to improve my coding ninja h4x skills, and I'm currently looking at
I'm part of a small team trying to start coding on a project. I've
I'm currently trying to learn WinSock coding from http://johnnie.jerrata.com/winsocktutorial/ however when I compile my
I'm trying to use this coding but its not processing, and its not outputing
I am coding for various programming olympiads and am trying to improve time efficiency.
I'm coding an app in Phonegap and I'm trying to extract the video-ID from

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.