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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:51:09+00:00 2026-06-11T23:51:09+00:00

A college freshman I know taking an intro to computer science class asked me

  • 0

A college freshman I know taking an intro to computer science class asked me for help on one of his homework assignments. I read through a few times and I’m embarrassed to admit I don’t know what they’re asking for. Here’s the question:

Given below is the outline of a loop. Finish the program so that it will read in x and y values, validate them (by continuing to prompt the user until they enter the correct values), and run such that the given assertions will always be true. Include the loop invariant assertion at the four points in your program where it must be true. You may not use the multiplication operator, except in the given assert(…) statements.

assert(x>0 && y>0);
while(...)
{
    assert(sum == i*(x+1));
    ...
    ...
}
assert(sum == y*(x+1));

I didn’t know what a loop invariant was so I googled and read the Wikipedia article. From that I gather the first assert statement is telling me that I should not allow x and y to ever be negative for the duration of the loop. Truthfully I’m stuck at this point. Can someone help me understand what they’re asking for here?

  • 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-11T23:51:10+00:00Added an answer on June 11, 2026 at 11:51 pm

    The description of the homework is incomplete to the point of being almost meaningless.

    However, one can infer that it is about letting the user enter two positive integers, and computing the product without using the multiplication operator, as a sum.

    Generally, a product of positive integers can be defined as sum in this way:

    2 times b = b + b
    (a + 1) times b = b + (a times b)

    with the cases for operands 1 and 0 inferred by requiring the general rules to hold.

    The similarity of the last equation, to the asserts you show, is probably not a coincidence.

    Anyway, it works nicely as a loop invariant. As you increase the loop variable the loop invariant still holds and ensures that you have a nice product around. So that when the loop is finished, the loop invariant’s constraint on that product, plus the value of the loop variable at this point, ensures that you have a product that is (easily reduced to) x*y.

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

Sidebar

Related Questions

I'm a freshman in college going for my computer science degree... I've programmed plenty
I am college student (computer science) and have just started a C# programming class.
I'm a freshman in college, who's taking a python coding class. Currently I'm working
I am a college student taking a intro to programming C#. That being said,
I'm a blind college student who is taking an introduction to programming class that
I'm a college CS freshman who wishes to learn a version control system well.
A college at work created a class with only static methods. Because he wants
I taken math in college (trigonometry, calculus II...) but I don't know why you
Back in college I wrote a game where the computer would sleep for 1
I was thinking back to my freshman year at college (five years ago) when

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.