Hit the Slopes

Write a program that can be used by a ski resort to keep track of loca

Page 1 of 1

7 Replies - 6254 Views - Last Post: 28 June 2011 - 04:32 PM Rate Topic: -----

#1 BigJohnson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 13-October 09

Hit the Slopes

Post icon  Posted 26 October 2009 - 04:41 PM

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 seven-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 seven-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 the results. Here is a 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


The problems I am having:
1) How can I keep the Date and Base together while sorting through the program to place the Base in order?
2) how can get the 7 week date from only entering the start and end date?

Current error in program:
52| expected `;' before ')' token
52| name lookup of `count' changed for new ISO `for' scoping
52| using obsolete binding at `count'
52| `;' before ')' token

THANKS!!!


#include <iostream>
using namespace std;

void sortArray(double [], int);
void showArray(double [], int);

int main()
{
	const int BASE = 7;
	const int DAY = 7;
	int sDate = 0;
	int eDate = 0;
	string month; 
	
	double snowAmount[BASE];
	
	cout << "Please enter name of Month: ";
	cin >> month;
	cout << "Please enter the starting date of the seven day period: ";
	cin >> sDate;
	cout << "Please enter the ending date of the seven day period: ";
	cin >> eDate;	   
	cout << "Please enter the " << BASE << " base snow depths" << endl;  
	cin >> snowAmount[0];
	cin >> snowAmount[1];
	cin >> snowAmount[2];
	cin >> snowAmount[3];
	cin >> snowAmount[4];
	cin >> snowAmount[5];
	cin >> snowAmount[6];
	
	sortArray(snowAmount, BASE);
	
	showArray(snowAmount, BASE);
	 
	cout << "Snow Report " << month << " " << sDate << " - " << eDate << endl;
  
  

	system ("PAUSE");
	return 0;
}	

void sortArray(double array[], int size)
{
	 int temp;
	 bool swap;
	 
	 do
	 { swap = false;
	 for (int count = 0; count < size - 1); count ++)
		 {
			  if (array[count] > array [count + 1])
			  {
				 temp = array[count];
				 array[count] = array[count + 1];
				 array[count + 1] = temp;
				 swap = true;
			  }
		 }
	 } while(swap);
}

void showArray(double array[], int size)
{
	 for (int count = 0; count < size; count++)
	   cout << array[count] << " " << endl;
}
	   



Is This A Good Question/Topic? 0
  • +

Replies To: Hit the Slopes

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6245
  • View blog
  • Posts: 24,013
  • Joined: 23-August 08

Re: Hit the Slopes

Posted 26 October 2009 - 05:34 PM

Here's your error report.
Current error in program:
52| expected `;' before ')' token
52| name lookup of `count' changed for new ISO `for' scoping
52| using obsolete binding at `count'
52| `;' before ')' token



You see that 52? That's the line number. You go to the code, you go to that line number, and you say...hmmm...what's wrong with code at this line:
for (int count = 0; count < size - 1); count ++)

and in ten seconds, you've got it figured out.

Instead, you go through the trouble of coming here and posting. Bizarre.
Was This Post Helpful? 0
  • +
  • -

#3 BigJohnson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 13-October 09

Re: Hit the Slopes

Posted 26 October 2009 - 07:09 PM

hahahah, man I am sorry about that one.... yes i know what the 52 means for some reason it just sliped over my head I am sorry, but the main reason of my post wasn't the error report it was

Quote

The problems I am having:
1) How can I keep the Date and Base together while sorting through the program to place the Base in order?
2) how can get the 7 week date from only entering the start and end date?



Thanks once again.
Was This Post Helpful? 0
  • +
  • -

#4 zhanfeng  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 75
  • Joined: 09-November 08

Re: Hit the Slopes

Posted 26 October 2009 - 07:20 PM

This is for you first question. You can have another array which stores the corresponding dates. For example,
date[0] = 13;
snowAmount[0] = 42.3;
When you sort your base, you will probably have to swap the values of 2 bases and while you do that you can do it to the date also.
Was This Post Helpful? 0
  • +
  • -

#5 BigJohnson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 13-October 09

Re: Hit the Slopes

Posted 26 October 2009 - 08:02 PM

Yes I am using the bubble sort method. and I have managed to move my sDate into the function, but I still confused on how I can move the sDate along with the snowAmount

#include <iostream>
using namespace std;

void sortArray(double [], int, int);
void showArray(double [], int, int);
void showDate(int [], int);

int main()
{
	const int BASE = 7;
	const int DAY = 7;
	int sDate = 0;
	int eDate = 0;
	string month; 
	
	double snowAmount[BASE];
	int showDay[DAY];
	
	cout << "Please enter name of Month: ";
	cin >> month;
	cout << "Please enter the starting date of the seven day period: ";
	cin >> sDate;
	cout << "Please enter the ending date of the seven day period: ";
	cin >> eDate;	   
	cout << "Please enter the " << BASE << " base snow depths" << endl;  
	cin >> snowAmount[0];
	cin >> snowAmount[1];
	cin >> snowAmount[2];
	cin >> snowAmount[3];
	cin >> snowAmount[4];
	cin >> snowAmount[5];
	cin >> snowAmount[6];
	
	sortArray(snowAmount, BASE, sDate);
	

	 
	cout << "Snow Report " << month << " " << sDate << " - " << eDate << endl;
	  showArray(snowAmount, BASE, sDate);
  

	system ("PAUSE");
	return 0;
}	


//sort Array
void sortArray(double array[], int size, int date)
{
	 double temp;
	 bool swap;
	 
	 do
	 { swap = false;
	 for (int count = 0; count < size - 1; count ++)
		 {
			  if (array[count] > array [count + 1])
			  {
				 temp = array[count];
				 array[count] = array[count + 1];
				 array[count + 1] = temp;
				 swap = true;
			  }
		 }
	 } while(swap);
}

//Show Array 
void showArray(double array[], int size, int date)
{
	 
	 
	 for (int count = 0; count < size; count++)
	   cout << " day " << date << " " <<  array[count] << " " << endl;
}

/*void showDate(int array[], int size)
{
	 for
}
*/


Was This Post Helpful? 0
  • +
  • -

#6 zhanfeng  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 75
  • Joined: 09-November 08

Re: Hit the Slopes

Posted 26 October 2009 - 08:10 PM

I don't see an array for date anywhere?... You need to pass the array of date into the sort and display functions, not sDate. Hint for sorting the dates along with your bases: do exactly what you did to swap the values for bases. I hope that is clear to you.

EDIT - Didn't spot your array for date. My mistake.

This post has been edited by zhanfeng: 26 October 2009 - 08:24 PM

Was This Post Helpful? 1
  • +
  • -

#7 BigJohnson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 13-October 09

Re: Hit the Slopes

Posted 26 October 2009 - 09:14 PM

THANK YOU SO MUCH!!!!

Final code:

#include <iostream>
using namespace std;

void sortArray(double [], int, int[], int);
void showArray(double [], int, int[], int);
void showDate(int [], int);

int main()
{
	const int BASE = 7;
	const int DAY = 7;
	int sDate = 0;
	int eDate = 0;
	string month; 
	
	double snowAmount[BASE];
	int showDay[DAY];
	
	cout << "Please enter name of Month: ";
	cin >> month;
	cout << "Please enter the starting date of the seven day period: ";
	cin >> sDate;
	cout << "Please enter the ending date of the seven day period: ";
	cin >> eDate;	   
	while (eDate != sDate +6)
	{
	cout << "Not a 7 day period." << endl;
	cout << "Please enter the starting date of the seven day period: ";
	cin >> sDate;
	cout << "Please enter the ending date of the seven day period: ";
	cin >> eDate;   
	}
	
	cout << "Please enter the " << BASE << " base snow depths" << endl; 
	cout << "Day " << sDate << ": ";
	cin >> snowAmount[0];
	cout << "Day " << sDate + 1 << ": ";
	cin >> snowAmount[1];
	cout << "Day " << sDate + 2 << ": ";
	cin >> snowAmount[2];
	cout << "Day " << sDate + 3 << ": ";
	cin >> snowAmount[3];
	cout << "Day " << sDate + 4 << ": ";
	cin >> snowAmount[4];
	cout << "Day " << sDate + 5 << ": ";
	cin >> snowAmount[5];
	cout << "Day " << sDate + 6 << ": ";
	cin >> snowAmount[6];
	
	
	showDay[0] = sDate;
	showDay[1] = sDate + 1;
	showDay[2] = sDate + 2;
	showDay[3] = sDate + 3;
	showDay[4] = sDate + 4;
	showDay[5] = sDate + 5;
	showDay[6] = sDate + 6;

	
	sortArray(snowAmount, BASE, showDay, DAY);
	

	cout << endl;
	cout << "Snow Report " << month << " " << sDate << " - " << eDate << endl << endl;
	  showArray(snowAmount, BASE, showDay, DAY);
  

	system ("PAUSE");
	return 0;
}	


//sort Array
void sortArray(double array[], int size, int day[], int sizeDay)
{
	 double temp;
	 bool swap;
	 int temp2;
	 
	 do
	 { swap = false;
	 for (int count = 0; count < size - 1; count ++)
		 {
			  if (array[count] > array [count + 1])
			  {
				 temp = array[count];
				 temp2 = day[count];
				 array[count] = array[count + 1];
				 day[count] = day[count +1];
				 array[count + 1] = temp;
				 day[count + 1] = temp2;
				 swap = true;
			  }
		 }
	 } while(swap);
}

//Show Array 
void showArray(double array[], int size, int day[], int sizeDay)
{
	 
	 
	 for (int count = 0; count < size; count++)
	   cout << " Day: " << day[count] << "  Base: " <<  array[count] << " " << endl;
}





Please enter name of Month: Dec
Please enter the starting date of the seven day period: 2
Please enter the ending date of the seven day period: 8
Please enter the 7 base snow depths
Day 2: 2.2
Day 3: 5.3
Day 4: 2.1
Day 5: 1.3
Day 6: 2.3
Day 7: 5.2
Day 8: 3.2

Snow Report Dec 2 - 8

Day: 5 Base: 1.3
Day: 4 Base: 2.1
Day: 2 Base: 2.2
Day: 6 Base: 2.3
Day: 8 Base: 3.2
Day: 7 Base: 5.2
Day: 3 Base: 5.3
Press any key to continue . . .
Was This Post Helpful? 0
  • +
  • -

#8 btfielder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-March 11

Re: Hit the Slopes

Posted 28 June 2011 - 04:32 PM

None of the answers to this thread deal with structures (as per requirements) so I thought I'd do that:


#include <iostream>
#include <string>
using namespace std;

struct SnowDate
{
       int date;
       double inches;
};

int main()
{
    string input_month;
    SnowDate snowWeek[7];
    SnowDate temp;
    int input_firstday, input_lastday; 
    int inc;    //incrementer
    bool swap;
    
    //gather input
    cout << "Enter the name of the month:";
    cin >> input_month;
    cout << "Enter the first and last day of the week:";
    cin >> input_firstday >> input_lastday;
    inc = input_firstday;
    for (int x=0;x<7;x++)
    {
          cout << "Enter the snowfall for day "<<inc<<":";
          cin >> snowWeek[x].inches;
          snowWeek[x].date = inc;
          inc++;
    }
    
    //sort by snowfall (bubble sort)
    do{
    swap = false;
    for (int x=0;x<6;x++)
    {
        if (snowWeek[x].inches > snowWeek[x+1].inches)
        {
           //copy struct to temp
           temp.inches = snowWeek[x].inches;  
           temp.date = snowWeek[x].date;
           //move the lowest up the array
           snowWeek[x].inches = snowWeek[x+1].inches;
           snowWeek[x].date = snowWeek[x+1].date;
           //copy temp to highest
           snowWeek[x+1].inches = temp.inches;
           snowWeek[x+1].date = temp.date;
           swap = true;
        }
    }
    }while(swap);
    
    //display
    cout << input_month<<" snow report for days "<<input_firstday<<"-"<<--inc<<":"<<endl;
    for (int x =0;x<7;x++)
    {
        cout << "Day: "<<snowWeek[x].date << " Base: " << snowWeek[x].inches<<endl;
    } 
    system("pause");
    return 0;
}


This post has been edited by btfielder: 28 June 2011 - 04:35 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1