Friday, July 31, 2009

Help with c++ program?

This is my 1st c++ course and i desparately in need of some help.I need a program that will print out the year with the most hurricanes. the program will input the name, month,and day the hurricane occur.please note this has to be multiple years say 2006,2005,2004 etc. I could do the program for 1 year but cannt do it for multiple years. also the hurricane has to occure in the season( june 1st to nov 1st). i appriciate any input. thanks in advance.

Help with c++ program?
Alright. Here's the deal.





Since this is your first course, here are some tricks.





If the program will have an input of name, month,and day the hurricane, then you will need 4 variables. A string and 3 integers.





How will you use them? How many times will you repeat the loop?





If you do not know how many times you want it to be repeated, then the wisest choice is a do/while. Otherwise, let the user tell you how many times it should be done.





You will make those 4 variables. They should be arrays, make sure they are big enough.





it will be something as simple as this:





let the user tell you how many times he want it to be repeated:





int timesToBeRepeated = 0;


cin %26gt;%26gt; timesToBeRepeated;





for ( int i = 0; i %26lt; timesToBeRepeated; i++ )


{





cout %26lt;%26lt;"Enter the Hurricane name: \n";


cin %26gt;%26gt; hurricaneName[i];


.


.


.


}





then, to print it out, just do something like this:





cout %26lt;%26lt;"Hurricane Name"%26lt;%26lt;" %26lt;%26lt;"Day"%26lt;%26lt;..%26lt;%26lt;endl;





then:





for ( i = 0; i %26lt; timesToBeRepeated; i++ )


cout %26lt;%26lt; hurricaneName[i] %26lt;%26lt;" "%26lt;%26lt;....%26lt;%26lt;endl;





Work out the rest, but that is pretty much it., Any doubt, contact me.
Reply:use an array that goes from 1-n where n is the number of years your data spans. Everytime a hurricane happens in that year, increment array[p] by 1 where p is the year of your data entry.





then loop from 1-n and look for the year with the biggest array[p] value


No comments:

Post a Comment