#include <iostream> // for CableBills
#include <iomanip>	// for formatting manipulators
#include <string>	// for string variables
#include <fstream>	// for file streams
using namespace std;

// Prototype Functions
void PrintHeading(ofstream& CableBills) ;			// Inout
void CustomerData(ofstream& CableBills,				
				  ifstream& CableRecs)  ;			// Inout
int  OutletCharge(int)					;
int	 ServiceCharge(char)				;			// Out


// Global Variables
int		totalOutlet;							
int		totalService;
int		totalTax;
int		totalTotal;
int		totalCustomers;

int main()
{
// Declaring Input variables
char		accountFirstName;				// Account First Name
char		accountLastName;				// Account Last Names
char		accountNumber;					// Account Number
char		date;							// Account Date
int			service;					// Nominal, Basic, or Premium (14.95, 34.95, 69.95 respectively
int			outlets;						// Amount of outlets purchased

// Declaring input and output file
ifstream CableRecs;		
ofstream CableBills;
CableRecs.open("CableRecs.txt");	// To attach CableRecs file to CableRecs
CableRecs.ignore(100, '\n');		// To ignore the first line of Cable Records
CableBills.open("CableBills.txt");	// The output file
	if (!CableRecs)					// In case the program can't read the file
		{	CableBills << "Unable to read file." << endl;
	return 1; 
		}

// Invoking PrintHeading function - Pass by reference		
PrintHeading(CableBills); 

// Reading data of the 1st customer (Priming Read)
CableRecs >> accountFirstName;
CableRecs >> accountLastName; 
CableRecs >> accountNumber; 
CableRecs >> date;
CableRecs >> outlets; 
CableRecs >> service;

while (CableRecs)	// Loop starts
	{
// Invoking OutletCharge 
OutletCharge(outlets);
// Invoking ServiceCharge function - Pass by value
ServiceCharge(service);

// Reading values from customer data
CableRecs >> accountFirstName;
CableRecs >> accountLastName; 
CableRecs >> accountNumber; 
CableRecs >> date;
CableRecs >> outlets; 
CableRecs >> service;

}	// End of Loop

// Closing input and output files
CableRecs.close();
CableBills.close();

	return 0;
}[
int ServiceCharge(char service,
				  int serviceCharge){
	const int		NOMINALFEE         = 1495;			// Charged if customer uses nominal service
	const int		BASICFEE           = 3495;			// Charged if customer uses basic service
	const int		PREMIUMFEE         = 6995;			// Charged if customer uses premium service
	const char		NOMINALCODE        = "N";			// Customer code for nominal service
	const char		BASICCODE          = "B";			// Customer code for basic service
	const char		PREMIUMCODE        = "P";			// Customer code for premium service
[b]
// Nominal service charges 14.95
	if ( service == NOMINALCODE) {
		serviceCharge = NOMINALFEE;
	}
// Basic service charges 34.95
	if ( service == BASICCODE ) {
		serviceCharge = BASICFEE;
	}
// Premium service charges 69.95
	if ( service == PREMIUMCODE ) {
		serviceCharge = PREMIUMFEE;
	[/b]}
return serviceCharge;
}

The purpose of this program is to read a data set of customers purchasing cable service and then calculating it out into order to make a transaction report in the end.

The problem I'm having is these error code come up when I try to run it.

(181): error C2440: 'initializing' : cannot convert from 'const char [2]' to 'const char'
(182): error C2440: 'initializing' : cannot convert from 'const char [2]' to 'const char'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
(183): error C2440: 'initializing' : cannot convert from 'const char [2]' to 'const char'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast

It points out to the bool coding on the ServiceCharge function.

Recommended Answers

All 4 Replies

Single character definitions require apostrophes (single quotes) while char arrays (strings) need quotes, for example:

char single_char = 'a';
char stringy[] = "character array";

Thanks. I got that part fixed. Now I ran into another problem after fixing that.

Cable Bills Functions error LNK2001: unresolved external symbol "int __cdecl ServiceCharge(char)" (?ServiceCharge@@$$FYAHD@Z)

Cable Bills Functions fatal error LNK1120: 1 unresolved externals

What does this mean?

It means the linker can't find the implementation of your ServiceCharge method, most likely because the declaration and definitions of the methods don't match.

Ah that fixed that problem. Now with that comes another problem -_-.

I'm gonna repost the code

#include <iostream> // for CableBills
#include <iomanip>	// for formatting manipulators
#include <string>	// for string variables
#include <fstream>	// for file streams
using namespace std;

// Prototype Functions
void PrintHeading(ofstream& CableBills) ;			// Inout
void CustomerData(ofstream& CableBills,				
				  ifstream& CableRecs)  ;			// Inout
int  OutletCharge(int)					;
int	 ServiceCharge(char,
				   int)				;			// Out

// Global Constants
const int		UTILITYTAX		   = 300;		// Flat lumpsum tax charged to all customers		
const int		MONCONVERT		   = 100;		// Used to convert into montary amount
const int		OUTLETFEE		   = 100;		// Outlet fee charged if customer has more than 1 outlet	
const double	REGTAXRATE		   = 0.0012;	// Regulatory Tax rate charged to every customer
// Global Variables
int		totalOutlet;							
int		totalService;
int		totalTax;
int		totalTotal;
int		totalCustomers;

int main()
{
// Declaring Input variables
char		accountFirstName;				// Account First Name
char		accountLastName;				// Account Last Names
char		accountNumber;					// Account Number
char		date;							// Account Date
int			service;						// Nominal, Basic, or Premium (14.95, 34.95, 69.95 respectively
int			outlets;						// Amount of outlets purchased
int			serviceCharge;					// Amount Charged for service purchased

// Declaring input and output file
ifstream CableRecs;		
ofstream CableBills;
CableRecs.open("CableRecs.txt");	// To attach CableRecs file to CableRecs
CableRecs.ignore(100, '\n');		// To ignore the first line of Cable Records
CableBills.open("CableBills.txt");	// The output file
	if (!CableRecs)					// In case the program can't read the file
		{	CableBills << "Unable to read file." << endl;
	return 1; 
		}

// Invoking PrintHeading function - Pass by reference		
PrintHeading(CableBills); 

// Reading data of the 1st customer (Priming Read)
CableRecs >> accountFirstName;
CableRecs >> accountLastName; 
CableRecs >> accountNumber; 
CableRecs >> date;
CableRecs >> outlets; 
CableRecs >> service;

while (CableRecs)	// Loop starts
	{

// Invoking ServiceCharge function - Pass by value
ServiceCharge(service,
			  serviceCharge);

[b]// Testing Output
cout << serviceCharge << endl;
cout << "Testing to see if this works!" << endl;[/b]

// Reading values from customer data
CableRecs >> accountFirstName;
CableRecs >> accountLastName; 
CableRecs >> accountNumber; 
CableRecs >> date;
CableRecs >> outlets; 
CableRecs >> service;

}	// End of Loop

// Closing input and output files
CableRecs.close();
CableBills.close();

	return 0;
}
void PrintHeading(ofstream& CableBills){
// Setting up Header of the Billing Report
	
	CableBills << "Placeholder Header" << endl;;
	return; 
}


//////////////////////////////////////////////////////////////////////////////////
//	Function to determine which service is charge per customer
//	Parameter:
//		service
//
//	This function requires the input of service 
//	
//	serviceCharge will be the determinant of the amount //      charged to the customer

int ServiceCharge(char service,
				  int serviceCharge){
        	
	const int		NOMINALFEE         = 1495;			// Charged if customer uses nominal service
	const int		BASICFEE           = 3495;			// Charged if customer uses basic service
	const int		PREMIUMFEE         = 6995;			// Charged if customer uses premium service
	const int		NOMINALCODE        = 'N';			// Customer code for nominal service
	const int		BASICCODE          = 'B';			// Customer code for basic service
	const int		PREMIUMCODE        = 'P';			// Customer code for premium service


// Nominal service charges 14.95
	if ( service == NOMINALCODE) {
		serviceCharge = NOMINALFEE;
	}
// Basic service charges 34.95
	if ( service == BASICCODE ) {
		serviceCharge = BASICFEE;
	}
// Premium service charges 69.95
	if ( service == PREMIUMCODE ) {
		serviceCharge = PREMIUMFEE;
	}
return serviceCharge;
}

My new problem is that while the compiler is able to run the program and give me no error message. I'm unable to give an output or cout out to test to see if serviceCharge is being changed. The header function of mines is able to output fine and dandy but for some reason after the serviceCharge or header function, it isn't outputting what I want to see. I'm not sure what's going on here...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.