Menu

Code Correction

mackmellow
2007-08-19
2012-09-26
  • mackmellow

    mackmellow - 2007-08-19

    Hi guys! I’m a new student of dev C++. I want to learn some of its basic fundamentals.
    A sample code here is to be corrected:

    include <iostream>

    using namespace std;

    int main ()
    {
    back:
    int age,bday,year;
    year = 2007;

    cout << “How old are you? \n“;
    cin >> age;
    if (age != ‘int’) {
    cout << “Please enter numeric value!\n”;
    goto back;
    }
    bday = year – age;
    cout << “You were born in” <<bday;
    return 0;
    }

    I need you to repair these codes. I want these codes when you enter your age,
    It should be a numeric value, if not, I want it to leave a message asking for a numeric value for age, and ask again for his age. If it enters numeric value for age, then it will just
    Simply display the year you were born. Thank a lot!...
    Great corrections will be heartily appreciated…

     
    • mackmellow

      mackmellow - 2007-08-22
      • What are the different types of classes used for
        object-oriented programming in C++?

      • Why is my Dev-C++ failed to compile and brings out a pop-up
        window which is a "riskware"?and if you'll going to quarantine
        or terminate and then compiles again, it will leave a message,
        "The system cannot find the path for a specified file".

       
      • Wayne Keen

        Wayne Keen - 2007-08-22

        (1) The kind that work, and the kind that don't

        (2) Poltergeist phenomenon, or an imbalance in the matter/anti-matter ratio
        leading to a temporal rift that trips your anti-viral software.

        I am sure your teacher will love those answers.

        Wayne

         
    • Wayne Keen

      Wayne Keen - 2007-08-19

      Why is my homework alarm bell going off?

      Wayne

       
      • Osito

        Osito - 2007-08-19

        LOL, it has a goto statement.

         
    • Anonymous

      Anonymous - 2007-08-19

      It seems to me that you don't want to learn anything at all; otherwise you would have paid attention in class!

      However I will teach you a few fundamentals:

      1) It is "repair this code" NOT "repair these codes".
      2) No one is a "student of dev C++", "C++" perhaps, but not "Dev-C++". That's like saying: "I am learning to use the Dell Insporion 6000" rather than "I am learning to use a PC".
      3) "goto" is IMO only supported in C/C++ for historical reasons (probably to make it easy to port unstructured Fortran code). It has no place in any code you should ever write.

      Clifford

       
    • mackmellow

      mackmellow - 2007-08-20

      sorry guyz!about those codes but im just trying to find some solution to make it work regarding on the statements above that
      i want to happen.i need a correction,not a comment, but if you
      can't make it,still fine,it's ok.thankz....!

       
    • Soma

      Soma - 2007-08-20

      That is by far the most bizarre attempt at C++ I've seen.

      "i need a correction,not a comment"

      Don't worry; the comments are on the house.

      Soma

       
      • Wayne Keen

        Wayne Keen - 2007-08-20

        Notice that he did not deny it is homework.

        Wayne

         
    • Kurgusov

      Kurgusov - 2007-08-20

      if (age != ‘int’) {

      Would that actualy work?

      and should put the label back: after the variable declarations,
      though a loop is better.

      theres my 2 cents of utter crap.

       
    • Anonymous

      Anonymous - 2007-08-20

      Don't bother to respond, he won't understand. He repeated the same grammatical error right after I corrected it in point (1).

      Clifford

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.