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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:37:20+00:00 2026-05-23T08:37:20+00:00

Alright, so here’s the portion of my code that is giving me a problem.

  • 0

Alright, so here’s the portion of my code that is giving me a problem. What I want it ot do is to take in a grade, decide if it is a valid grade, and then keep asking for a valid number if it is not. However, it won’t even enter the loop, so…. any advice? Ive been programming for a little bit but Im still pretty new, so extra explanations are great! Also this is my first time using booleans in a for loop.

for (bool b_valid=false; b_valid=false ; )
{
cin >> n_grade;
b_valid = true;
    if (n_grade>100 || n_grade<0)
        {
            cout << "Invalid grade: Re-enter a number between 0-100 : " << endl;
            cin >> n_grade;
            b_valid = false;
        }
}
  • 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-23T08:37:20+00:00Added an answer on May 23, 2026 at 8:37 am

    Your condition is an assignment: b_valid=false. It will evaluate to false and the loop will never execute. You meant

    for(bool b_valid = false; b_valid == false; )
                                     ^^^^ 
    

    There is a coding style which mandates that the constant in comparison be the first argument, like if(false == b_valid). In this case, if you accidentally typed = , you’d get a compiler error. In any case many compiler give a warning in cases where you had written assignment where a boolean expression was expexted. Either yours wasn’t as sofisticated, or you just ignored the warning.

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

Sidebar

Related Questions

Alright so here is my issue. I'm working a game engine that will eventually
Alright so here is the deal. I am trying to make a application that's
Alright, I'm trying to read a comma delimited file and then put that into
Alright here's the situation, I have an application written in the Zend_Framework, that is
Alright, here goes. I'm making a very basic app, and I want the user
[EDIT] Alright, I edited this post since the code I posted back then had
Alright, currently I have my SWF hitting a php file that will go and
Alright here's the deal, I'm taking an intro to C++ class at my university
I'm trying to generate ics-files, see sample here: http://deap.nu/myprogram.ics It validates alright here: https://icalendar.org/validator.html
Alright, here's my current test function: function make_void( str ) { var str_arr =

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.