Thread: A question about a question

  1. #1
    Registered User
    Join Date
    Jan 2010

    Question A question about a question

    Can someone explain this question? I don't want the answer, just an explaination. I can write the program easy enough but what does the rest of the question mean?

    6.Write a piece of code that will demonstrate a logical error in a program that was designed to calculate the average of three test grades. Be sure to make it clear to me what the logical error is, explain if necessary.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Well having made it work, you introduce a bug so that it doesn't work.
    Then you explain your bug.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Apr 2010
    More specifically, your professor wants to know that you understand the concept of a logical bug (as opposed to a syntactic bug). The idea is that the program compiles, but does not produce the correct results.

    An example: a program that is supposed to determine the maximum of 2 numbers input by the user, but instead outputs the minimum. The logical error is highlighted in red.

    #include <iostream>
    using namespace std;
    int main()
        int i1, i2, iMax;
        cout << "Please insert your first number: ";
        cin >> i1;
        cout << endl << "Please insert your second number: ";
        cin >> i2;
        iMax = i1;
        if (i2 < i1)
            iMax = i2;
        cout << endl << "The highest number was " << iMax << endl;
        return 0;

  4. #4
    Registered User
    Join Date
    Jan 2010

    Lightbulb Thank you

    Vey helpful.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM