Hi all,

I am a self learner and getting dificulty to solve this. Can any body help me out and let me know where I am going wrong.

Thanks in advance...............................

Write a program that can be used by a ski resort to keep track of local snow conditions for one week. It should have a 7 -element array of structures, where each structure holds a date and the number of inches of snow in the base on that date. The program should have the user input the name of the month, the starting and ending date of the 7 day period being measured, and then the seven base snow depths. The program should then sort the data in ascending order by base depth and display results.

Sample report:

Snow Report December 12-18

Date Base
13 42.3
12 42.5
14 42.8
15 43.1
18 43.1
16 43.4
17 43.8

Coding:-------#include <iostream>#include<iomanip>#include<string>using namespace std;struct DaysStruct{ int month; int st_date; int end_date; DaysStruct(int i,int e) { st_date = i; end_date = e; } };struct BaseStruct{ int date; int end_date; double snow_depth;};//Function prototypes void calcDays(DaysStruct[],BaseStruct[],int);void sortbyBase(BaseStruct[],int);void showOrder (BaseStruct[],int);int main(){ const int NUM_DAYS = 7; DaysStruct days[NUM_DAYS] = { DaysStruct(12), // days[0] = st_date; DaysStruct(13), //days[1] = days[0] + 1; DaysStruct(14), //days[2] = days[1] + 1; DaysStruct(15), //days[3] = days[2] + 1; DaysStruct(16), //days[4] = days[3] + 1; //days[5] = days[4] + 1; // days[6] = end_date; DaysStruct(17), DaysStruct(18), }; BaseStruct base[NUM_DAYS]= {cout<< " Enter the seven base snow depths", cin >> base[0],base[1],base[2],base[3],base[4],base[5],base[6],base[7] }; calcDays (days,base,NUM_DAYS); sortbyBase(base,NUM_DAYS); cout<< fixed << showpoint << setprecision(2); showOrder(base,NUM_DAYS); system("PAUSE"); return EXIT_SUCCESS;}void calcDays(DaysStruct days[],BaseStruct base[],int num){ for(int index=0; index< num; index++) { base[index].st_date = days[index].st_date; base[index].end_date = days[index].end_date; cout<<"Enter the month"<<endl; cin>>month; cout<< "Enter the starting date of the 7-day period"<<endl; cin>>st_date; cout<<"Enter the ending date of the 7-day period"<<endl; cin>>end_date; }void sortbyBase(BaseStruct base[], int elems){ int startScan,maxIndex; SalesStruct maxValue; for (startScan = 0; startScan< (elems-1); startScan++) { maxIndex = startScan; maxValue = base[startScan]; for ( int index = startScan+1; index<elems; index++) { if (base[index].snow_depth > maxValue. snow_depth) { maxValue = base [index]; maxIndex = index; } } base[maxIndex] =base [ startScan]; base[startScan] = maxValue; } } void showOrder(BaseStruct base[], int num) { cout<< "Date \t \t Base \n"; cout<<"-----------------------------\n"; for( int index =0; index < num; index++) { cout << base[index].st_date<<\t \t <<endl; cout<<setw(8) << base [index].snow_base<<endl; } cout<< endl; }

Salem commented: Learn how to post before asking questions! -1

Recommended Answers

All 5 Replies

I hope you don't expect anyone to read that stuff you posted :-O

Here is formatted code:

#include <iostream>
#include<iomanip>
#include<string>
using namespace std;
struct DaysStruct
{
    int month;
    int st_date;
    int end_date;
    DaysStruct(int i,int e)
    {
        st_date = i;
        end_date = e;
    }
}
;
struct BaseStruct
{
    int date;
    int end_date;
    double snow_depth;
}
;//Function prototypes
void calcDays(DaysStruct[],BaseStruct[],int);
void sortbyBase(BaseStruct[],int);
void showOrder (BaseStruct[],int);
int main()
{
    const int NUM_DAYS = 7;
    DaysStruct days[NUM_DAYS] = { DaysStruct(12),
                                  // days[0] = st_date; DaysStruct(13),
                                  //days[1] = days[0] + 1; DaysStruct(14),
                                  //days[2] = days[1] + 1; DaysStruct(15),
                                  //days[3] = days[2] + 1; DaysStruct(16),
                                  //days[4] = days[3] + 1; //days[5] = days[4] + 1;
                                  // days[6] = end_date;
                                  DaysStruct(17), DaysStruct(18), };
    BaseStruct base[NUM_DAYS]=
        {
            cout<< " Enter the seven base snow depths", cin >> base[0],base[1],base[2],base[3],base[4],base[5],base[6],base[7]
        }
        ;
    calcDays (days,base,NUM_DAYS);
    sortbyBase(base,NUM_DAYS);
    cout<< fixed << showpoint << setprecision(2)
    ;
    showOrder(base,NUM_DAYS);
    system("PAUSE");
    return EXIT_SUCCESS;
}
void calcDays(DaysStruct days[],BaseStruct base[],int num)
{
    for(int index=0; index< num; index++)
    {
        base[index].st_date = days[index].st_date;
        base[index].end_date = days[index].end_date;
        cout<<"Enter the month"<<endl;
        cin>>month;
        cout<< "Enter the starting date of the 7-day period"<<endl;
        cin>>st_date;
        cout<<"Enter the ending date of the 7-day period"<<endl;
        cin>>end_date;
    }
    void sortbyBase(BaseStruct base[], int elems)
    {
        int startScan,maxIndex;
        SalesStruct maxValue;
        for (startScan = 0; startScan< (elems-1); startScan++)
        {
            maxIndex = startScan;
            maxValue = base[startScan];
            for ( int index = startScan+1; index<elems; index++)
            {
                if (base[index].snow_depth > maxValue. snow_depth)
                {
                    maxValue = base [index];
                    maxIndex = index;
                }
            }
            base[maxIndex] =base [ startScan];
            base[startScan] = maxValue;
        }
    }
    void showOrder(BaseStruct base[], int num)
    {
        cout<< "Date \t \t Base \n";
        cout<<"-----------------------------\n";
        for( int index =0; index < num; index++)
        {
            cout << base[index].st_date<<\t \t <<endl;
            cout<<setw(8) << base [index].snow_base<<endl;
        }
        cout<< endl;
    }

;-)

>Can any body help me out and let me know where I am going wrong.
Well, what's wrong with it?

And you're quite lucky that someone as nice as ~s.o.s~ reformatted your code; I don't even know how you managed to paste that unreadable mess in the first place...??

I am sorry that I posted it messy.Being the first time or what I don't know how it had happened.
I copied from my DEVC++ and pasted it here.
Thanks for S.O.S for reformating the same code. It's not compiling properly.Can anybody please help me.

The actual problem is this:
Write a program that can be used by a ski resort to keep track of local snow conditions for one week. It should have a 7 -element array of structures, where each structure holds a date and the number of inches of snow in the base on that date. The program should have the user input the name of the month, the starting and ending date of the 7 day period being measured, and then the seven base snow depths. The program should then sort the data in ascending order by base depth and display results.

Sample report:

Snow Report December 12-18

Date Base
13 42.3
12 42.5
14 42.8
15 43.1
18 43.1
16 43.4
17 43.8

>It's not compiling properly.
Well, what are the errors??!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.