C++ coding problem

So for a homework assignement i was suppose write a C++ program to determine which movie production is the most cost-effective domestically and globally based on the provided movie data. A gross profit is in US dollars. One way to measure the cost effective-ness is to take the ratio between the gross profit and production budget. The movie data are stored in a text file, where each field is separated by a whitespace. Each movie record has four fields: movie name, productionbudget, domestic gross and worldwide gross. There are 103 records in total. Please use an array of C++ structure to build the movie database from the title. The struct is provided below.
s t r u c t Movie {
s td : : s t r i n g name ;
double budget ;
double dome s t i c g r o s s ;
double g l o b a l g r o s s ;
} ;
Please use the concept of modular programming to divide and conquer
the tasks into functions and display proper outputs. For each function, it
should have a meaningful name and clear objective.
1. Determination of the most cost-effective movie production domestically.
2. Determination of the most cost-effective movie production globally.

Here is my code and im getting this str != NULL debug error. Someone please help.

#include <iostream>
#include <string>

using namespace std;
struct movie
{
string movieName;
double budget, domestic_gross, global_gross;
};

void domestic_cost(movie &);
void global_cost(movie &);

int main()
{
movie m;
char c, filename[25];
FILE *fp;
char line[80];

cout << "Enter the file you wish to open\n";
gets(filename);

fp = fopen(filename, "r+");

if (fp = NULL)
{
perror("Error while opening the file.\n");
exit(EXIT_FAILURE);
}
cout << "The contents of %s file are :\n" << filename;
while ((fgets(line, 80, fp)) != NULL)
{
for (int i = 0; i < 80; i++){
printf("%c", line[i]);
}
fclose(fp);
return 0;
}
void domestic_cost(movie &m);
{
float cost_effective;
float budget, domestic_gross, global_gross;

//get movie name
cout << "Enter title of the movie: ";
cin >> m.movieName;

// get budget
cout << "Enter the budget: ";
//cin.getline(m.budget);
cin >> m.budget;

// cin >> m.movieName >> m.budget >> m.domestic_gross >> m.global_gross;


// get domestic gross
cout << "Enter the domestic gross: ";
cin >> m.domestic_gross;

cost_effective = domestic_gross / budget;
cout << cost_effective;
}
void global_cost(movie &m);
{
float cost_effective;
float budget, domestic_gross, global_gross;

//get movie name
cout << "Enter title of the movie: ";
cin >> m.movieName;

// get budget
cout << "Enter the budget: ";
cin >> m.budget;

// get domestic gross
cout << "Enter the domestic gross: ";
cin >> m.global_gross;

cost_effective = global_gross / budget;
cout << cost_effective;
}
}

Last edited on
I straight c/p'ed your code and compiled fine (after including the missing libs ofc) - you dont evaluate *fp you try to set it NULL. The correct should be if(fp == NULL) - however I dont believe that is the source if your compiler error.

Also are you sure you compile the right project? I dont see any str variable if your code for the compiler to complain about.
Last edited on
Topic archived. No new replies allowed.