Hi im trying to build this pay rate calculator but im getting a few errors:

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

struct Time{
	int hr, min;
	char meridian;
};

struct Garage{
	string name;
	float rate;
	Time time_in, time_out;
};

struct PayRecord{
	string name;
	string position;
	int ssn;
	int vacdays;
	int weekly_hrs;
	float weakly_sal;
};

int main(){
	Garage car;

	car.name = "Wednesday";
	car.rate = 12.50;
	
	cout<<"Enter time you parked your car (ie 12 30 a): ";
	cin>>car.time_in.hr>>car.time_in.min>>car.time_in.meridian;
	cout<<"Enter time you picked up your car (ie 12 30 a): ";
	cin>>car.time_out.hr>>car.time_out.min>>car.time_out.meridian;

	cout<<"THE RATES FOR THE GARAGE LISTED IS:"<<endl
		<<"Day: \t\t" + car.name<<endl
		<<"Rate: \t\t$"<<fixed<<setprecision(2)<<car.rate<<endl
		<<"TimeIn: \t"<<car.time_in.hr<<":"<<car.time_in.min<<car.time_in.meridian<<"m"
		<<endl
		<<"TimeOut: \t"<<car.time_out.hr<<":"<<car.time_out.min<<car.time_out.meridian<<"m"
		<<endl;
//////////////////////////////////////////////////////////////////////////////////////////////


	const int NUM = 5;
	//PayRecord staff[5];
	PayRecord staff[NUM] = {
				{"Alice", "CEO", 101, 10, 40, 25.00},
				{"Bob", "Manager", 102, 5, 40, 15.00},
				{"Carl", "Junior Manager", 103, 5, 35, 10.00},
				{"Dan", "Sales Associate", 104, 2, 0, 8.50},
				{"Ellen", "Sales Associate", 105, 1, 0, 8.50}
			};

	return 0;
}

Recommended Answers

All 9 Replies

Add code tags to around your code. And what kind of errors are you getting ? You need to elaborate.

The following is the error i keep getting:

--------------------Configuration: Lab4Part2 - Win32 Debug--------------------

E:\CompSci\Part2\Part2.cpp(56) : error C2440: 'initializing' : 
		cannot convert from 'char [6]' to 'struct PayRecord'
        No constructor could take the source type, or constructor overload 
		resolution was ambiguous
E:\CompSci\Part2\Part2.cpp(56) : error C2440: 'initializing' : cannot 
		convert from 'char [4]' to 'struct PayRecord'
        No constructor could take the source type, or constructor overload resolution 
		was ambiguous
E:\CompSci\Part2\Part2.cpp(56) : error C2440: 'initializing' : cannot convert 
		from 'const int' to 'struct PayRecord'
        No constructor could take the source type, or constructor overload resolution 
		was ambiguous
E:\CompSci\Part2\Part2.cpp(56) : error C2440: 'initializing' : cannot convert 
		from 'const int' to 'struct PayRecord'
        No constructor could take the source type, or constructor overload resolution 
		was ambiguous
E:\CompSci\Part2\Part2.cpp(56) : error C2440: 'initializing' : cannot convert 
		from 'const int' to 'struct PayRecord'
        No constructor could take the source type, or constructor overload resolution 
		was ambiguous
E:\CompSci\Part2\Part2.cpp(56) : error C2440: 'initializing' : cannot convert 
		from 'const double' to 'struct PayRecord'
        No constructor could take the source type, or constructor overload resolution was 
		ambiguous
E:\CompSci\Part2\Part2.cpp(56) : fatal error C1903: unable to recover from previous 
		error(s); stopping compilation
Error executing cl.exe.

Very strange, the code you posted compiles for me with VC++ 2008. The errors indicate that the compiler is having trouble initializing your structure elements. Are you sure there are no differences between the code you posted and that you are compiling ?

Im using Visual C++ 6.0 and there is no difference im still not able to compile any other method i can compile this?

well if you have access to linux, you could try compiling the code using gcc.

Are you sure your environment is pointing to the correct header files and libraries ? You could also comment out the lines where you initialize the stucture values at the end to narrow down if that is causing the errors.

I do not have access to linux :(.

But for what i see and ive tried it in a different pc that runs the same program i keep on getting the same errors.

I'd suggest commenting out lines 50 - 56 and see if your error goes away, then you know what your exact problem is.

Also check the options of your VC6.0 to make sure that it is pointing to the correct include, lib and bin directories.

That compiler is not fully c++ compliant and contains several bugs. If you want to compile that then you may have to use a different compiler.

>>Also check the options of your VC6.0 to make sure that it is pointing to the correct include, lib and bin directories.

I tried to compile with VC++ 6.0 and mine failed too for the same reason. The problem has nothing to do with header files.

It will compile if you replace string in the structure with char*.

output:

Enter time you parked your car (ie 12 30 a): 12 30
a
Enter time you picked up your car (ie 12 30 a): 1 0 a
THE RATES FOR THE GARAGE LISTED IS:
Day: Wednesday
Rate: $12.50
TimeIn: 12:30am
TimeOut: 1:0am
Press any key to continue

Thanks for the info Ancient Dragon. I recently uninstalled my VC6.0 ..

For Nasi23,
You could install the express version of MSVC++ 2008. That is free, and I guess more compatible.

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.