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
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?
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.
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.
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.
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?
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.
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.
#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 ;
}
constint 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");
}