I am getting an error in Windows Vista that says "Project3.exe has stopped working", and has a bar like a loading a bar, and under it, it says it is looking for a solution. The program is an class assignment that takes a data fiile with information about energy usage and can do different things with that information. This is my code ( The code is unfinished, i was just testing this first function)
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <stdint.h>
using namespace std;
void option1 ( int energy[29][14], string types[13], int64_t total[29] )
{
short int year;
short int i;
float percent[13];
restart:
cout << "Enter the year: ";
cin >> year;
if ( year < 1980 || year > 2008 )
{
cout << "Year must be at least 1980 and at most 2008!\n";
goto restart;
}
year = year % 29;
cout << setprecision ( 3 ) << setiosflags ( ios::fixed ) << setiosflags ( ios::showpoint );
for ( i = 0; i < 28; i++ )
{
percent[i] = ((float) total[year] )/ energy[year][i];
}
cout << "Energy Source" << setw ( 50 ) << "Energy in Megawatt Hours" << setw ( 80 ) << "Percent of Total Energy\n";
for ( i = 0; i < 13; i++ )
{
cout << types[i] << energy[year][i+1] << percent[i] << "\n";
}
}
int main()
{
int energy[29][14];
int64_t fossilfuel[29];
int64_t renewable[29];
int64_t total[29];
string types[13] = {"Coal","Petroleum","Natural Gas","Other Gases","Nuclear","Hydro-Electric Pumped Storage","Hydro-Electric","Biomass - Wood","Biomass - Waste","Geothermal","Solar","Wind","Other"};
int r, c;
short int option;
ifstream energyfile("energy.dat");
for ( r = 0; r < 29; r++ )
{
for ( c = 0; c < 13; c++ )
{
energyfile >> energy[r][c];
}
}
for ( int i = 0; i <= 28; i++ )
{
fossilfuel[i] = 0;
renewable[i] = 0;
total[i] = 0;
for ( c = 1; c <= 4; c++ )
{
fossilfuel[i] += energy[i][c];
total[i] += energy[i][c];
}
total[i] += energy[i][5];
total[i] += energy[i][6];
for ( c = 7; c <= 12; c++ )
{
renewable[i] += energy[i][c];
total[i] += energy[i][c];
}
total[i] += energy[i][13];
}
cout << "Please enter an option:\nOption 1. Input a year and display a result with energy uses for each energy type.\nOption 2. The peak year of production of a certain energy type.\nOption 3. Create a data file to be opened by Excel." << endl;
cin >> option;
switch ( option )
{
case 1:
option1 ( energy, types, total );
break;
case 2:
//option2 ( energy );
break;
case 3:
//option3 ( energy);
break;
}
cin.ignore();
cin.get();
return 0;
}
I figured it was a problem with the arrays, like i was accessing them wrong or something, but i checked them and it looked fine. any help would be appreciated.