Results 1 to 3 of 3

Thread: Can u fix this?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    NY State
    Posts
    145

    Can u fix this?

    // Rob Gross
    // Midterm
    // 3/11/02
    // Due Thursday


    #include <iostream>
    using namespace std;

    int main ()

    {
    int days [12] = {31,28,31,30,31,30,31,31,30,31,30,31};
    int difference;
    int fmonth;
    int fdate;
    int smonth;
    int sdate;

    cout << "Enter your first Month and Date: " << endl;
    cin >> fmonth >> fdate;
    cout << "Enter your second Month and Date: " << endl;
    cin >> smonth >> sdate;

    difference = (days [fmonth - 1] - fdate);

    cout << difference << " days between the dates. " << endl;

    return 0;
    }

    My computer crashes on this line

    difference = (days [fmonth - 1] - fdate);

    what is wrong is that I have it set to nothing.

    The point of this project is to calculate the number of days that the user enters when they enter a month and a date twice.

    You understand?
    ICQ = 20476917
    AIM = Butnud

    Lets Talk!

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Although I don't understand what this line shall accomplish, the pogra works for me. You might be giving it wrong input. Valid would be for example:
    3 12
    7 25

    Then fmonth would be 3, fdate 12, smonth 7 and sdate 25.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    If you want the day difference between two dates, here is a working program (yours a little bit modified)
    Code:
    int main () 
    { 
    int days [12] = {31,28,31,30,31,30,31,31,30,31,30,31}; 
    int difference; 
    int fmonth; 
    int fdate; 
    int fdays = 0;
    int smonth; 
    int sdate; 
    int sdays = 0;
    int i;
    
    cout << "Enter your first Month and Date: " << endl; 
    cin >> fmonth >> fdate; 
    cout << "Enter your second Month and Date: " << endl; 
    cin >> smonth >> sdate; 
    
    for(i = 0; i < fmonth-1; i++)
    	fdays += days[i];
    fdays += fdate;
    
    for(i = 0; i < smonth-1; i++)
    	sdays += days[i];
    sdays += sdate;
    
    difference = (sdays - fdays); 
    
    cout << difference << " days between the dates. " << endl; 
    
    return 0; 
    }
    Note: for more readability, always wrap your code in [ code]-[/ code] or [php ]-[/php ] tags (without the spaces)
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width