1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Lost In C

Discussion in 'C' started by creative, Mar 25, 2010.

  1. creative

    creative New Member

    Joined:
    Feb 15, 2010
    Messages:
    87
    Likes Received:
    0
    Trophy Points:
    0
    i need to make a function that calculates the highest and lowest months ,total rain fall and average rain fall can any one please help i am lost



    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int getActualRain(int j);
    string print_month(int month);
    //char January, February;
    
    
    int main()
    
    {
    int i;
    float AverageRain[13];
    float ActualRain[13];
    
    
    for (i = 1; i < 13; i++)
    {
    cout << "Enter average Monthly Rainfall for " << print_month(i) << ": ";
    cin >> AverageRain[i];
    }
    
    int month;
    cout << "Please enter current month: " << endl;
    cin >> month;
    
    
    return 0;
    }
    
    string print_month(int month)
    {
    string result;
    switch (month)
    {
    case 1:
    result = "January";
    break;
    case 2:
    result = "February";
    break;
    case 3:
    result = "March";
    break;
    case 4:
    result = "April";
    break;
    case 5:
    result = "May";
    break;
    case 6:
    result = "June";
    break;
    case 7:
    result = "July";
    break;
    case 8:
    result = "August";
    break;
    case 9:
    result = "September";
    break;
    case 10:
    result = "October";
    break;
    case 11:
    result = "November";
    break;
    case 12:
    result = "December";
    break;
    default:
    cout << "Invalid Value!\a";
    break;
    }
    return result;
    }
     
  2. techinspiration

    techinspiration New Member

    Joined:
    Feb 14, 2010
    Messages:
    54
    Likes Received:
    0
    Trophy Points:
    0
    Here is Something for you a easy One.
    Code:
    struct CalculateRain
    {
    	double rain;
    	char *Month;
    
    };
    int main(int argc, char **argv)
    {
    CalculateRain MyRainArr[3];
    double Averagerain =0;
    	for(int i=0;i<3;i++)
    	{
    		cout<<"Enter The Month"<<endl;
    		MyRainArr[i].Month = new char[255];
    		cin>>MyRainArr[i].Month;
    		cout<<"Enter The rain Now"<<endl;
    		cin>>MyRainArr[i].rain;
    	}
    	cout<< "Hre is your Month and rain"<<endl;
    	for(i=0;i<3;i++)
    	{
    		cout<<MyRainArr[i].Month<<" "<<MyRainArr[i].rain<<endl;
    		
    	}
    	cout<<"Average rain is"<<endl;
    	for(i=0;i<3;i++)
    	{
    		Averagerain+=MyRainArr[i].rain;
    	}
    	cout<<"Average Rain is "<< Averagerain/i;
    
    	for(i=0;i<3;i++)
    	{
    		delete [] MyRainArr[i].Month;
    	}
      return 0;
    }
    
    Now i think Minimaum and maximum rain Month you can calculate with your Self.if Still Problem Please Let us Know
     
  3. creative

    creative New Member

    Joined:
    Feb 15, 2010
    Messages:
    87
    Likes Received:
    0
    Trophy Points:
    0
    Anyway, thanks!
    I'll check it and will post result soon...
    :D
     

Share This Page