Instructions:
--For each day, tell which balloon (identify it by time released) traveled the greatest distance on that day (7 values printed). Identify the day by name rather than by number.
--For each day, calculate and print the average distance (print one decimal position) traveled by all balloons released on that day which were actually recovered hose for which distance > 0) (7 values printed). Identify the day by name rather than by number.
--Calculate and print the average distance (print one decimal position) traveled by all the balloons which were recovered during the entire week (1 value printed).
--I am pulling my information from a file where its listed like:
4 1200 182
4 1800 42
7 1500 284
first column means day
second column means time
third column means distance traveled
I am very new to c++ and still learning a lot. I am using bloodshed Dev c++ Thanks for your time

Here is my code: You don't have to tell me the answer I just need guidance on completing the program like should I use switch statements, more void function, etc.

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
                                          
const int DAYS=7;             // Global constants
const int TIME=5;
// function prototypes
void getInfile( double distance [DAYS][TIME]);
void avgDistance(double distance[][TIME]);
void dayRelease(double distance[][TIME]);
int maxDistance(double distance [][TIME], int);
void printHeading(string[]);


int main()
{
    string dayNum[DAYS]= { " Sun. ", " Mon. ", " Tues. ", " Wed. ", " Thurs. ", " Fri. ", " Sat. "};
    string timeRelease[TIME]= { " 600 ", " 900 ", " 1200 ", " 1500 ", " 1800 "};
    
    double distance[DAYS][TIME]; // 2D array for storing the distance values
    int day; // row subscript for distance array
    int time; // column subscript for distance array
    int max; // subscript for the largest distance in a row
    double sum;
    double totalSales;
    
       

   getInfile (distance);                    		     // Input values to fill the store array.
   printHeading(dayNum);
   
   for (day = 0; day < DAYS; day++) 				// For each day
   {
      		       			    	
      		max = maxDistance (distance, day);    // find the largest distance in distance array
              sum = dayRelease(distance, day);    				

        cout << setw(15) << left << timeRelease[TIME]; 
 
        for (time = 0; time < TIME; time++)  		
	            cout << setw(10) << right << distance [day][time];
            																														
        cout << setw(10) << sum << "  " << left << dayNum[max] << endl;
   }                                        								


   
    system("pause");
}

Not using Dev-C++ is a good idea. There are plenty of free compilers available, and if you're using Windows I would recommend Visual Studio 2010 express.

The reason Dev-C++ is bad is because it's old, unsupported, and buggy.

http://www.microsoft.com/express/Downloads/

Basically the problem with your code is that you haven't implemented the functions yet, which I'm sure you're aware of.

In my experience, it's best to keep the program as flexible as possible by abstracting details from the programmer (yourself, which may make it even easier).

So instead of defining an array of times (as a string you will need to parse),
why not make it work for any time by not knowing all the times?
(You'll need to parse the string or the double value because you're using a matrix of double values).

A design decision you will need to make is if you want to read the file multiple times, or store the entire file's contents in memory (which can be a big problem if the file is gigantic).

The algorithm for reading the file's data could simply be:

string day, time;
unsigned distance;
inFile >> day >> time >> distance;

Edited 5 Years Ago by pseudorandom21: matrix, not array.

I have visual studio c++ on my computer but it won't allow me to run my programs and so I stuck with the compiler my teacher originally recommended. Ok so I have completed the program but I keep getting an error message. Also I want to know am I doing this program right because I feel like I am missing something. Thanks
54 a function-definition is not allowed here before '{' token
71 a function-definition is not allowed here before '{' token
84 a function-definition is not allowed here before '{' token

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
                                          
const int DAYS=7;             // Global constants
const int TIME=5;
// function prototypes
void getInfile( double distance [DAYS][TIME]);
void avgDistance(double distance[][TIME]);
int maxDistance(double distance [][TIME], int);
void printHeading(string[]);


int main()
{
    string dayNum[DAYS]= { " Sun. ", " Mon. ", " Tues. ", " Wed. ", " Thurs. ", " Fri. ", " Sat. "};
    string timeRelease[TIME]= { " 600 ", " 900 ", " 1200 ", " 1500 ", " 1800 "};
    
    double distance[DAYS][TIME]; // 2D array for storing the distance values
    int day; // row subscript for distance array
    int time; // column subscript for distance array
    int max; // subscript for the largest distance in a row
    double sum;
    double totalSales;
    
       

   getInfile (distance);                    		     // Input values to fill the store array.
   printHeading(dayNum);
   
   for (day = 0; day < DAYS; day++) 				// For each day
   {
      		       			    	
      		max = maxDistance (distance, day);    // find the largest distance in distance array
              
        cout << setw(15) << left << timeRelease[TIME]; 
 
        for (time = 0; time < TIME; time++)  		
	            cout << setw(10) << right << distance [day][time];
            																														
        cout << setw(10) << dayNum[max] << endl;
   }                                        								
  void getInfile (double distance [DAYS][TIME])   //
{
   int day;
   int time;
   ifstream infile ("balloons.txt");

   for (day = 0; day < DAYS; day++)
   {
       for (time = 0; time < TIME; time++)
  	      			infile >> distance [day][time];
       infile.get();  // to read the newline
   }       // end of for each store
   getInfile(distance);
}

// calculating the maximum distance   

int maxDistance (double distance [ ][TIME], int r)       
{
   int max;
   int time;

   max = 0;            // Assume first value in the row is largest
   for (time = 1; time < TIME; time++)
        if (distance[r][time] > distance [r][max])
	           max = time;
   return max;
   max=maxDistance(distance, day);
}
// Print heading
void PrintHeadings(string dayNum[])
{
   cout << "\n                              Balloons\n\n";
   cout << setw(64) << right << "Days                  Time"
     	<< "   Greatest\n";
   cout << "Days            ";
   for (int time = 0; time < TIME; time++)
       cout << setw(10) << left << timeRelease[time];
   cout << "  Total Average Distance\n\n";
}


    system("pause");
}

return max;
max=maxDistance(distance, day);
}

How on earth is the program going to go past that return?

The skeleton of the program is going to be like this, the function definitions are not inside the main function.

#include <iostream>
//Whatever else includes.

int foo();//<-- function prototype or function declaration

int main()
{
//Body of the main function
}

int foo()
{
//Function definition
}
This article has been dead for over six months. Start a new discussion instead.