problem with a code.

Pages: 12
class include_function { // new class called include function

public:

long datetoday (string date)
{
string day, month, year;
long totalday;
if ((date[2]=='/' && date[5]=='/') && (date.length() == 10)) // date to day calculation
{
day = day + date[0]+ date[1];
month = month + date[3] + date[4];
year = year + date[6] + date[7] + date[8] + date[9];
totalday = atoi(day.c_str()) + ((30 + ((atoi(month.c_str()) % 9) %2)) * (atoi(month.c_str()))) + (atoi(year.c_str()) * 365);
return totalday;
}
else
cout << "Invalid Date..";

return 0;

}


How can i make this piece of code work ?
Last edited on
closed account (4Gb4jE8b)
is it a compiler issue? is it always returning invalid date? is it just not returning what you want it to? We don't usually do all of the book work ourselves, you have to tell us what's going on and what you're trying to do as well.

And yes, we can read code. it looks like your main problem is with your if statement

note: by we, i am refering to the many kind people on this forum, though i do not intend to speak for any specific person, just the actions taken on this forum in general
Last edited on
Im using CodeBlocks. The error msg says atoi is not declared .

I cant figure out whats the problem.

any1 could troubleshoot for me?

Doing a room booking system ; Data Structure
thx to all the kind ppl out there. really appreciate ur works. u guys are an artist. =)
Are you including cstdlib?
Last edited on
#include<iostream>
#include <vector> // vector Library
#include <string>
#include<fstream> // file stream Library
#include<iomanip>

using namespace std;

#ifndef BOOKING
#define BOOKING

/////////////////////////////////////////////////////////////////////////

should i include cstdlib ?
yes. atoi is defined and implemented in that header.
thx so much. i havent had much sleep for the pass 3 days. 1 more question... how about strlen ?

what header should i implement?
cstring

But just for future reference, you're not implementing those headers, you're including them, there's a bit a difference.
Thx for d info n help. appreciate it
Now i have a diff problem.

It can be compile, but how can i make a data file where i can save a record in it ?

any tips on this ?
http://www.cplusplus.com/reference/iostream/fstream/

Read up on this class and how to use it.
closed account (4Gb4jE8b)
yep, that's pretty much it, though if your using fstream, i suggest you read up on stringstreams as well, as they often go hand in hand

http://www.cplusplus.com/reference/iostream/stringstream/
I've actually never used string streams in my entire life.
string read_input(string filename,int line, char delimeter)
{
string str1, str2;
char next;
int a=0;
ifstream fin;
fin.open(filename.c_str());
if (fin.fail()) {cout << "Data file disappear!" << endl; exit(1);}
do{
fin.get(next);
if (next==delimeter){
str2=str1;
a++;
str1="";}
else
str1 = str1+next;
}while ((!(fin.eof())) && (!(a>line)));
return str2;
}


from here what should i do ??
Last edited on
should i copy everything here of what i have done ?? my code is still not working. SOS
whats d diff between fstream.h with just fstream ???
closed account (4Gb4jE8b)
you just include <fstream>, at your level, i'm honestly gonna say don't worry about fstream.h

@seraphimsam haha, i'm surprised, but it's probably because i'm using MS visual studio 2010 that i was forced into it so quickly. I'm not able to use regular strings or c strings with fstreams at all.
dude, make sure you use the code format brackets.... it will be a lot more helpful

I think the latter return statement or something... I never used return 0 within an if statement. Can someone please tell me if that's alright... does return 0 simply mean that the current block of code was executed fine? I thought that meant that the whole block of program completed successfully and it's alright to terminate the program.

Also can you post the whole entire source code page... That will definitely help us. and make sure you use the code format brackets please :)
Last edited on
im gona open another topic for the whole code
Pages: 12