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's my problem. I'm trying to write a script in PHP that
Alright, so here's the dealio: I'm working on a Ruby app that'll take data
Alright so here is my code, I get the result I want but I
Alright...I am here looking for some bread crumbs. This is my code: using System;
Alright, here I am again trying to write code from scratch and I can't
Alright, here goes. I'm making a very basic app, and I want the user
Alright I'm totally baffled. Here's my code: if ($password == $correct_password[0] && !isset($_COOKIE['user'])) {
Alright, so I'm making a Facebook-style chat. But that doesn't really matter. See here:
Alright here's the code: //in another file void **ptr; ptr = kmalloc(sizeof(void *) *
Alright here is the thing, I have this site that was once wordpress but

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.