I'm relatively new to programming, and when I first compiled this program I got a whole slue of errors and slowly whittled it down to the last outstanding error which was for line 93, I had
Code:
fin.open(file_name)
and fixed it by making it
Code:
fin.open("file_name")
but when I tried to compile it after that I got an error that I can't make any sense of. the error reads:
Code:
/usr/local/gcc/lib/gcc/sparc-sun-solaris2.10/4.5.2/crt1.o: In function `.nope':
/usr/local/src/gnu/gcc/gcc-4.5.2/gcc/config/sparc/sol2-c1.asm:94: undefined reference to `main'
collect2: ld returned 1 exit status
I don't have a function '.nope' and i'm not sure what the undefined reference to the main 'main' is given that I haven't even crated a main file yet. Can anyone help me out with this?
Code:
#include <iostream>#include <cstdlib>
#include <fstream>
#include <string>
#include "MyTime.h"
using namespace std;
MyTime::MyTime(){
hours = 0;
minutes = 0;
simplify();
}
MyTime::MyTime(int& time1, int& time2){
time1 = hours;
time2 = minutes;
}
void MyTime::set_time(int time1, int time2){
hours = 0;
minutes = 0;
simplify();
}
int MyTime::get_time1()const{
return hours;
}
int MyTime::get_time2()const{
return minutes;
}
istream& operator >> (istream& ins, MyTime t1){
char selection1, selection2;
string file_name;
ifstream fin;
int num1 = 0, num2 = 0, tmp1 = 0, tmp2 = 0;
cout << "Do you want to input the number of hours and minutes now or from a file? (enter N for now and F for file): ";
cin >> selection1;
while (selection1 != 'n' && selection1 != 'N' &&
selection1 != 'f' && selection1 != 'F'){
cout << "Please enter a valid selection. N or F: ";
cin >> selection1;
}
if (selection1 == 'n' || selection1 == 'N'){
cout << "Enter the number of hours: ";
ins >> t1.hours;
cout << "Enter the number of minutes: ";
ins >> t1.minutes;
}
else if (selection1 == 'f' || selection1 == 'F'){
cout << "Please enter the name of the file that has the number of minutes and hours: ";
cin >> file_name;
fin.open("file_name");
if (fin.fail()){
cout << "The file " << file_name << " does not exsist in this folder, please put the file into this folder " << endl
<< " or hole CRTL + C to close out of this program: ";
cin >> file_name;
}
while (fin >> num1 >> num2){
tmp1 += num1;
tmp2 += num2;
}
cout << "Your file has a total of " << tmp1 << " hours and " << tmp2 << " minutes. If this is backwards and the totals " << endl
<< "should be " << tmp2 << " hours and " << tmp1 << " minutes and you would like the correct this please type Y, and if you "<< endl
<< "do not wish to correct this type N: ";
cin >> selection2;
while (selection2 != 'y' && selection2 != 'Y' &&
selection2 != 'n' && selection2 != 'N')
cout << "Please enter a valid selection, Y or N: ";
cin >> selection2;
if (selection2 == 'n' || selection2 == 'N'){
t1.hours = tmp1;
t1.minutes = tmp2;
ins >> t1.hours >> t1.minutes;
}
else if (selection2 == 'y' || selection2 == 'Y'){
t1.hours = tmp2;
t1.minutes = tmp1;
ins >> t1.hours >> t1.minutes;
}
}
return ins;
}
void MyTime::simplify(){
int tmp1, tmp2;
if (minutes >= 60){
tmp1 = minutes / 60;
tmp2 = minutes % 60;
hours += tmp1;
minutes += tmp2;
}
}