My Comp Sci 2 class....

This is a discussion on My Comp Sci 2 class.... within the Windows Programming forums, part of the Platform Specific Boards category; Originally posted by moi the program WILL return something to the operating system. if you void main (), then either: ...

  1. #16
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by moi
    the program WILL return something to the operating system. if you void main (), then either:

    1: the compiler will correct your error and return a value to the os
    2: random garbage will be returned to the operating system
    3: your program will crash
    Of course it will return something, but the point is that you have no idea hat that could be....

    When the runtime assignes the return value to the int which it sends to exit(), it simply does a mov instruction on the value of the EAX register......

    It doesnt access memory or anything so you wont experience a crash, but its still very bad practice and if the runtime was part of the code you were compiling then it wouldnt even compile with a void main

  2. #17
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Fordy, as accurate and correct as what u just said prolly is, that makes no sense to me whatsoever, does that come in english? :P

  3. #18
    Shadow12345
    Guest
    I'm pretty sure your teacher is just using void main so she doesn't have to explain what return values are...I mean if you are still writing "hello world!" programs I think trying to explain return values would short circuit most of yours (and her) brains.

  4. #19
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    today(monday) is the first day of actual programming we just went back to school the 4th and the network wasn't ready yet(go figure).

    And she did say shed be going over it so....the year will tell.

  5. #20
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Ok new question but i didn't wanna make a new thread for it. She gave us our text book today(brand new!), i just want your opinion on it if you've ever read it, it has SOME void in it but quickly changes to int main and such:

    The Fundamentals of C++ Second Edition

    by: Lambert Nance

  6. #21
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by Ride -or- Die
    Ok new question but i didn't wanna make a new thread for it. She gave us our text book today(brand new!), i just want your opinion on it if you've ever read it, it has SOME void in it but quickly changes to int main and such:

    The Fundamentals of C++ Second Edition

    by: Lambert Nance
    Dont know...here's a review of another of their books......not promising

    here

  7. #22
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Well i realized there isn't any void main so thats good lol. He seems to explain it well and all *shrug*

    I went ahead a little and just started doing the programs (i'll read tonight :P) One answer i couldn't find was what this one line means and the one header. Heres the code and the two lines are commented off by astericks(*)

    //Program file chkbook.cpp
    //This program updates a checkbook
    //9-9-02

    #include <iostream.h>

    /***********************
    #include <iomanip.h>
    *********************/

    int main ()
    {
    double startingbalance, endingbalance, transamount;
    char transtype;

    //Module for getting the data.

    cout<<"Enter the Starting Balance abd press <enter>: ";
    cin>>startingbalance;
    cout<<"Enter the Transaction Type (D) Deposit or (W) Withdrawl ";
    cout<<"And press <enter>: ";
    cin>>transtype;
    cout<<"Enter the transaction amount and press <enter>: ";
    cin>>transamount;

    //Module for performing computations.

    if (transtype == 'D')
    endingbalance = startingbalance + transamount;
    else
    endingbalance = startingbalance - transamount;

    //Module for displaying results

    /************************************
    cout<<setiosflags(ios::fixed | ios::showpoint | ios::right)<<setprecision(2);
    /************************************

    cout<<endl;
    cout<<"Starting Balance $"<<startingbalance<<endl;
    cout<<"Transaction $"<<transamount<<" "<<transtype<<endl;
    cout<<"Ending Balance $"<<endingbalance<<endl;

    return 0;

    }

  8. #23
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    It is another header, similar to iostream, however, it includes the functions for formatting output. setiosflags and setprecision are defined inside that header.

  9. #24
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    so why isn't it declared like the other header files?

  10. #25
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    huh???

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 08:10 AM
  2. Specializing class
    By Elysia in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2008, 04:30 AM
  3. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 01:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21