So for my homework i have to create 3 files, a main, a functions, and a header file.
The program is supposed to calculate the charges for a internet company based on package inputted in hours inputted. We have to declare all the functions in the function file then use them in the main file. So far i have all the functions written but have no idea how to get them to work in the main.cpp
Any suggestions would be appreciated!
Functions (updated)
next time it would be helpful if you post the whole error, with the line so we can look faster in your errors.
getpck(char pck);
your way of calling of the function is wrong because getpck() doesn't accept parameters and more over, pck is declared as string, in the global scope and yet you declared it again as char,, you should remove char pck since it's useless
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-MacOSX/functions1
mkdir -p build/Debug/GNU-MacOSX
rm -f build/Debug/GNU-MacOSX/functions.o.d
g++ -c -g -MMD -MP -MF build/Debug/GNU-MacOSX/functions.o.d -o build/Debug/GNU-MacOSX/functions.o functions.cpp
functions.cpp: In function 'int validpck()':
functions.cpp:28: error: ISO C++ forbids comparison between pointer and integer
functions.cpp:28: error: ISO C++ forbids comparison between pointer and integer
functions.cpp:30: error: ISO C++ forbids comparison between pointer and integer
functions.cpp:30: error: ISO C++ forbids comparison between pointer and integer
functions.cpp:32: error: ISO C++ forbids comparison between pointer and integer
functions.cpp:32: error: ISO C++ forbids comparison between pointer and integer
make[2]: *** [build/Debug/GNU-MacOSX/functions.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
i have made the following changes to the header and functions:
#ifndef HEADER_H
#define HEADER_H
char getpck ();
int gethr ();
int validpck ();
int calculateA ();
int calculateB ();
int calculateC ();
int showbill ();
#endif /* HEADER_H */
char pck;
int hours;
double hoursover;
double planhours;
double plancost;
double overage;
double total;
char getpck ()
{
cout<<"Enter Package ID: ";
cin>>pck;
return pck;
}
int validpck ()
{
if ((pck == "a")||(pck == "A")){
int calculateA ();
}elseif ((pck == "b")||(pck == "B")){
int calculateB ();
}elseif ((pck == "c")||(pck == "C")){
int calculateC ();
}else {//user did not input correct package id
cout<< "invalid input.";
return (0);
}
return 0;
}
int gethr ()
{
cout<<"Enter Hours: ";
cin>>hours;
return hours;
}
Everything else is unchanged. My reason for changing the string to 'char' was because i was getting an error about not being able to convert a string to int. changing it to a 'char' got rid of the error but brought up this new one.
Alright that did fix the error. I am now getting the prompt for inputting the hours and package. But it doesnt seem to be using the inputted data in the validpck function to run the calculations.
EI
Enter Package ID: a
Enter Hours: 60
Amount due: 0
RUN FINISHED; exit value 0; real time: 2s; user: 0ms; system: 0ms
remember when calling functions, we don't include the return type:
this int calculateA ();, should be this calculateA();
the simple reason behind your error is possibly you call the function calculateA() but that function doesn't have return statement so automatically whenever you call the function 0 is returned instead
Do you mean in the functions code? or the header? I tried changing both of them to what you said and i got an error saying that it had to be defined.
Wait i got it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
int validpck()
{
if ((pck == 'a')||(pck == 'A')){
calculateA();
}elseif ((pck == 'b')||(pck == 'B')){
calculateB();
}elseif ((pck == 'c')||(pck == 'C')){
calculateC();
}else {//user did not input correct package id
cout<< "invalid input.";
return 0;
}
return 0;
}
works fine now. I just didnt understand where you were saying i needed to change it.
Thank you all for helping me! I was planning for a long night of research and frustration. I know i am on here basically every week with a new problem but i am learning. Nice to know you guys are always willing to help out!