program out puts only 1 with numbers

** This is the file *** I need to generate the totals sales for the first seven weeks of a movie

(FILE)
6
American-Sniper 1042 829 132347 81319 41008 29598 22258
Fifty-Shades-of-Grey 0 0 0 0 0 0 106902
Hunger-Games-Mockingjay 9600 4869 2641 1292 716 531 423
Imitation-Game 10516 10389 9899 9275 7077 6273 5223
Paddington 0 0 27671 14363 9868 6289 7178
Taken-3 0 48786 19664 9252 5024 2946 1471


(C++)

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>

using namespace std;

void boxtotals(string filename)
{
int N;
int i;
int movie;
int week1,week2,week3,week4,week5,week6,week7;

ifstream file;
file.open(filename.c_str());
if (!file.is_open())
{
cout << "** File unable to open **" << endl;
exit(-1);
}

file >> N;
int sum = 0;

for (i = 1; i <= N; i = i + 1)
{
file >> movie;
file >> week1;
file >> week2;
file >> week3;
file >> week4;
file >> week5;
file >> week6;
file >> week7;

sum = (week1 + week2 + week3 + week4 + week5 + week6 + week7);
cout << movie << ": " << sum;

}

file.close ();
return;
}


int main()
{
cout << "** Movie Box Office Totals for First 7 Weeks of 2015 **" << endl;
cout << endl;
boxtotals("movies.txt");
cout << endl;
cout << endl;

cout << "** Done **" << endl;

return 0;
}
Last edited on
The type of movie needs to be string not int
Topic archived. No new replies allowed.