Code is closing out after entering month.

closed account (D4NbpfjN)
So when i run my code it is closing down the program without running it after i enter the month. I have been looking over it trying to find the error, but i need a little help. I posted the directions i have to go by and the code i have started. Thanks in advance for the help.



Snow Fall Program: Write a program that can be used by a ski resort to keep track of local snow conditions for one week. It should have two seven-element arrays to store the date and number of inches of snow. First, the program should ask the user to enter the name of the month. Then, it should have the
user enter dates (dates does not need to be in sequential order) and corresponding snow fall. Once data is entered, store them in two arrays mentioned above. Then, the program should produce a report for the
week with following information. Use arrays to store snowfall and corresponding dates.

a) Highest snow fall.
b) Average snow fall.

Here is a sample report
Snow Report December
=================
Date Snow Fall
1 89.00
5 67.98
12 56. 83
13 12.45
16 100.67
20 78.76
25 34.65
The highest snow fall is 100.67 on 16th and the average snow fall is 62.90







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  #include<iostream>
#include<iomanip>
#include<string>
using namespace std;
int main()

{
	const int NumberDays = 7;
	int date[NumberDays];
	double snowfall[NumberDays];
	double highestsnowfall;
	int highestsnowdate;
	int count;
	double total = 0;
	string months[]={ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
	int month;
	
	cout << "Please eneter the name of the month:" << endl;
	cin >> month;
	
	for (int index = 0; index < NumberDays; index++)
	{
		cout << "Please enter the date of the snowfall " << index + 1 << endl;
		cin >> date[index];

		cout << "Please enter the amount of the snowfall." << endl;
		cin >> snowfall[index];
	}

	cout << fixed << showpoint << setprecision(2);
	cout << "\n\n\tSnow report for " << months[month - 1] << endl;
	cout << "\t\t" << endl;

	for (int index = 0; index < NumberDays; index++)
	{

		cout << months[month - 1] << " " << date[index] << "\t\t Snowfall " << snowfall[index] << endl;
	}

	highestsnowfall = snowfall[0];


	for (int count = 0; count < NumberDays; count++)
	{
		total += snowfall[count];

		if (snowfall[count] > highestsnowfall)
			highestsnowfall = snowfall[count];
		highestsnowdate = date[count];


	}



	cout << "\n\nThe highest snow fall total is " << highestsnowfall << " inches on the " << highestsnowdate << endl;
	cout << "\nThe average snow fall is " << total / NumberDays << " inches" << endl;

	system("pause");






	return 0;
}
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/129573/
closed account (D4NbpfjN)
i just checked that out and whats happening in my code is that it is asking all of it at once then it is closing the program. I am not sure if it is my laptop or the program?
So who is the other poster nsmith1779? interesting the code is exactly the same? Do you have multiple accounts and asking the same questions - or are you trolling?
closed account (D4NbpfjN)
there the same because i was testing the program and wasn't getting the right thing. But i have changed the program now to see if it is running correctly.
closed account (48T7M4Gy)
Either that or dylan has been working on this for 2 years.

I've wasted my time on another one of dylans projects that he's been working on for 8 years. Remarkable dedication and persistence. ;)

The pity is people with genuine concerns and a genuine interest to learn take one look and go somewhere else.

http://www.cplusplus.com/forum/beginner/192893/



Last edited on
Any good reasons why you should not be known as a troll?

If you purposefully waste our time, things won't go well for you.
closed account (D4NbpfjN)
no i have just started on this code. i only have one account. I did not know we couldn't look at another code and see how it is running and then build your own code. Sorry for all the mess.
closed account (D4NbpfjN)
no i am honestly not trying to waste your time. the help has been very helpful. it helps me understand it more. I was not trying to cause anything bad.
closed account (D4NbpfjN)
I do apologize for this. Wasn't trying to cause any trouble. Just trying to understand the programs better.
closed account (48T7M4Gy)
All the best dylan. I think we're done here.
closed account (D4NbpfjN)
I'm sorry I caused a mess, but i do appreciate your help. you did help me understand the program better and what i could do to write a program. I was not trying to waste anyone's time just get help.
I did not know we couldn't look at another code and see how it is running and then build your own code.


Not impressed, that could still be seen as troll behaviour. You seem to at least admit to serial plagiarism. I for one am not keen to help a plagiarist.
I'd say the existing code from previous posts can be a valuable resource. Maybe it is the way the questions were asked which was a little misleading. There's a difference between saying something like "I found this code written by someone else, can you help me to understand it", rather than giving the impression it was entirely your own work. In some ways maybe you were unlucky, there could be a completely correct and working code somewhere on the forum. But If you find and copy that, how much do you actually learn?
closed account (D4NbpfjN)
yes i understand and i do apologize. Not going to use the code i was running. I want to come up with my own. I was not trying to do any harm what so ever. Just trying to better understand the code.
closed account (D4NbpfjN)
yes your right and that is what i was meaning by it was that the code was helpful but copying does not get you anywhere you are right. I just wanted to better understand it before i wrote a code so that when i write it i know i was doing it correctly. I honestly was not trying to copy anyone's code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<iostream>
#include<iomanip>
#include<string>

int main()
{
    // put in an extra "invalid" at position zero so that we won't need to do month-1 every time
    const std::string months[13] = { "invalid", "January", "February", "March", "April", "May", "June", 
                                     "July", "August", "September", "October", "November", "December" };
    int month;

    std::cout << "Please enter the the month (January==1,December==12): " ;
    std::cin >> month;
    if( month < 1 || month > 12 )
    {
        std::cout << "invalid month\n" ;
        return 1 ;
    }

    const int NumberDays = 7;
    int date[NumberDays];
    double snowfall[NumberDays];

    for( int index = 0; index < NumberDays; ++index )
    {
        std::cout << "Please enter the date of the snowfall " << index + 1 << ": " ;
        std::cin >> date[index];
        // TO DO: validate that date[index] is a valid date

        std::cout << "Please enter the amount of the snowfall: " ;
        std::cin >> snowfall[index];
        // TO Do: validate that snowfall[index] is not negative
    }

    std::cout << std::fixed << std::setprecision(2)
              << "\n\n\tSnow report for " << months[month] << "\n\n" ;

    for( int index = 0; index < NumberDays; ++index )
    {
        std::cout << months[month] << " " << date[index] << "\t\tSnowfall " << snowfall[index] << '\n' ;
    }

    double highestsnowfall = snowfall[0] ;
    int highestsnowdate = date[0] ;
    double total = snowfall[0] ;

    for( int index = 1; index < NumberDays; ++index ) // start with 1
    {
        total += snowfall[index] ;
        if( snowfall[index] > highestsnowfall )
        {
            highestsnowfall = snowfall[index] ;
            highestsnowdate = date[index] ;
        }
    }

    std::cout << "\n\nThe highest snow fall is " << highestsnowfall << " inches on "
              << months[month] << ' ' << highestsnowdate
              << "\n\nThe average snow fall is " << total / NumberDays << " inches\n" ;

    // std::system("pause");
}
Topic archived. No new replies allowed.