C++

Discussion in 'Web Design & Coding' started by JJH35, Dec 16, 2002.

  1. JJH35

    JJH35 OSNN Addict

    Messages:
    140
    ive got this program i need it to output the weeks days an hours correctly according to the number of hours entered, i got the Weeks and Hours to come out but i cant get the Days what would i have to do,
    for example if a user enters 70 hours it should output
    Weeks:1
    Days:3
    Hours:6
    but i cant get the Days to come out right
    and it has to workfor more than just 70hours, like if i put in 85 the Days should be zero
    thanx
     
  2. Khayman

    Khayman I'm sorry Hal... Political User Folding Team

    Messages:
    5,518
    Location:
    England
    70 hours is 2days 22 hours

    the way i would do it (theres probably an easier way), something like this, probably not correct syntax
    do
    {
    if (input_hours >= 24)
    {
    days=days+1
    if (days >= 7) weeks = weeks +1
    input_hours=input_hours -24
    }
    else if (input_hours > 0) hours =input_hours
    }while input_hours > 24
     
  3. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    I'd do:
    Code:
    // The hours you input must be an integer.
    weeks = input_hours / (24*7);
    input_hours = input_hours % (24*7);
    days = input_hours / 24;
    hours = input_hours % 24;
    
     
  4. Luna64

    Luna64 Guest

    Perhaps if you show us the code, we can point out your mistake ?
     
  5. ReC0iL

    ReC0iL Guest

    I heard C++ is hard as hell if you don't know what you are doin...
     
  6. Luna64

    Luna64 Guest

    Well it can be :)

    I took a year of it in college.

    The language is easy to learn. I had a really had time with OOP code though :(

    Still don't understand it at all.

    But basic C++ is very, very simple.
     
  7. ReC0iL

    ReC0iL Guest

    Thats what everyone told me
    :D
     
  8. dave holbon

    dave holbon Moderator

    Messages:
    1,014
    Location:
    London England
    Anyone who says that C++ is simple has an IQ of 300 or above. Simple is Visual Basic and it’s variants and even then to use it efficiently takes one year of study followed by two of developing a “real” application. This is because there are so many ways of doing things especially if you’re not to worried about error trapping and the like. C++ and C programmes can never be verified as being correct or even bug free as for every way you can perform a given simple action there are ten thousand other ways of doing the same thing. C# has gone some way to circumventing this problem especially involving error trapping. However the environment that they all run-in on just about all computers today was itself written in C or C++. It’s like building a house within which another house resides then asking the (inside house) where the windows are in the (real or outside) house, the answer could be right or wrong but the point is you have no way of knowing which is correct.
     
  9. Luna64

    Luna64 Guest

    Dave Holbon,

    C++ is not hard to learn.

    If you try and teach yourself, you will probably fail.
    Take a C++ class. It is really simple.


    And just because you can do something a million different ways in C++ does not mean that you are not going to know the outcome. That's what makes it an advanced language. That's also what gives it power over Visual Basic. You are not set to many rules or laws.
     
  10. dave holbon

    dave holbon Moderator

    Messages:
    1,014
    Location:
    London England
    The very nature of the C programming language and its derivatives are the main reason (in my opinion) why companies like Microsoft have a stranglehold on the operating system and related application markets throughout the entire world. Developing an operating system like XP (for instance) required thousands of expensive programmers all working in harmony or at least to some sort of set goal. Only multi-billion-dollar Corporations can do this. Indeed anyone contemplating a “new” operating system is looking at ten to twenty billion dollars development costs just to enter the market. Still think C is simple?

    At the other end of the spectrum is the Visual whatever type scripting languages used not only for quick application development but also for modelling. No one in any commercial environment today would consider using C or C++ for developing (say) database applications if for no other reason than you end up with a product that is specific to the developer and probably incompatible with the rest of the worlds systems. This is already a major problem. My main point concerning C is that it’s not disciplined enough, gives the programmer the means to crash any machine on which it is run and worst of all allows “duff” programmers (you know the ones that say if it compiles ok then it must be ok) to continue their practice without let or hindrance and there are plenty of them working in large organisations usually relegated to the “device driver” department or such low status environments.

    I don’t know what the answer to this is but I’m sure of one thing: There needs to be a vast leap in programming languages development. This area is about ten years out of date with only the size of the current programming code increasing every year but not the functionality or speed. Software is getting slower and bigger.
     
  11. Luna64

    Luna64 Guest

    Well C is really old, so we cant really fix it up any longer.

    I have yet to learn C#, but I guess they are taking a Java route with it.


    Advanced software requires an advanced language which is why C/C++ & Java are around. Visual Basic (in my oponion) is for smaller applications usually made by a single person. It's great for when I need to create a program for school, but even then I find myself doing it in Visual C++ instead. Still I don't know much VB, so it could be a stronger language then I think it is.


    I guess what all this is leading to is that C/C++ give you complete control over what you are doing. VB does not. You tell it what you want and it kinda does most of it for you. Why would a large company want VB ?

    I just hope, as you said, there is some leap in programming. C++ takes a long time to learn. And even then you don't know it all. So I am still learning it. And making it all work together is a real pain.
     
  12. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    I'll have to agree with Dave, C++ is hard.

    Sure basic C/C++ is really simple and what not, but when you start messing with pointers and looking after memory leaks, that's when you sometimes start to wonder if the computer does what it does (crash and burn) just to spite you.

    We've had a lab course about operation systems this fall and all the labs are in C++ (NACHOS). You couldn't dream about the errors we got. Completely insane. We eventually found most of them, some of them by misstake or by rewriting our code from scratch.


    God I hate NACHOS. :mad: *sigh*
     
  13. Luna64

    Luna64 Guest

    Yea, high lvl C++ is crazy.

    I just finished low lvl C++, though I thought it was beyond simple.


    I just hate when I get an error and I have no idea where it is comming from :huh:

    I end up searching for about an hour and it turns out I was a silly typo or something.
     
  14. dave holbon

    dave holbon Moderator

    Messages:
    1,014
    Location:
    London England
    Some the most difficult bugs I’ve ever encountered concern data type coercion concerning memory pointers and returned values (or not). This area in C is a minefield of bugs, misunderstandings and pure ignorance. However the understanding of it, in it’s entirety, would take you about three years to understand completely.

    :) :) :) :) :) :) :)
     
  15. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    Yeah I know what you mean. We had a really annoying error in one of the labs. It resulted in a pretty much random error, Bus Error, Segmentation Fault, you name it. Sometimes it worked. Really annouying. Turned out to be a "-1" missing on one line. Two fricking characters in about 40 pages of code. Not easy to find! Took a few weeks.