Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Help~! I don't know what's wrong with this program.

Reply
Thread Tools

Help~! I don't know what's wrong with this program.

 
 
titan0111@hotmail.com
Guest
Posts: n/a
 
      12-13-2004
#include<iostream>
#include<iomanip>
#include<cstring>
#include<fstream>
using namespace std;

class snowfall
{
private:
int ft;

float in;
float totalsfin;

char date[6];

static int validcount;
static int invalidcount;

public:
void readdata(ifstream& infile)
{
infile>> ft >> in >> date;
}

void writedata(ofstream& outfile)
{
outfile<< ft << in << date;
}

void updatevalidcount()
{
validcount++;
}

void updateinvalidcount()
{
invalidcount++;
}

void calctotalsf()
{
totalsfin += float(ft)*12 + in;
}

int getft()
{return ft;}

float getin()
{return in;}

char* getdate()
{return date;}

int getvalidcount()
{return validcount;}

int getinvalidcount()
{return invalidcount;}

int operator == (char[]);
char datavalid();
void writetotalsf(ofstream& outfile);
};

int snowfall:perator == (char sf[])
{
return (strcmp(date, sf) == 0) ? 1 : 0;
}
char snowfall::datavalid()
{
char valid;

if ((ft >= 0) && (in >= 0.0f))
valid = 'T';
else
valid = 'F';
return valid;
}
void snowfall::writetotalsf(ofstream& outfile)
{
int totalsfft = 0;

if (totalsfin >= 12.0f)
while (totalsfin <= 11.0f)
{
totalsfft++;
totalsfin -= 12.0f;
}

outfile<< "/nThe total amount of snowfalls: " << totalsfft
<< " feet " << totalsfin << " inches.\n";
}


void main()
{
snowfall sf[10];
snowfall validsf[10];
snowfall invalidsf[10];

void writetitle(ofstream&);
void writeheadings(ofstream&);
void sortsf(snowfall);
void writevalidsf(snowfall, ofstream&);
void writeinvalidsf(snowfall, ofstream&);


ifstream infile;
ofstream outfile;

infile.open("c:\\downloads\\input.txt");
outfile.open("c:\\downloads\\output.txt");

if (infile && outfile)
{
int j = 0;
int k = 0;

writetitle(outfile);

for (int i = 0; i <= 10; i++)
{
sf[i].readdata(infile);

if (sf[i].getdate() == "00/00")
i = 10;
else
{
if (sf[i].datavalid() == 'T')
{
validsf[j] = sf[i];
sf[i].updatevalidcount();
sf[i].calctotalsf();
j++;
}
else
{
invalidsf[k] = sf[i];
sf[i].updateinvalidcount();
k++;
}
}
}

sortsf();
writeheadings(outfile);
writevalidsf(outfile);
writeinvalidsf(outfile);
validsf[i].writetotalsf(outfile);
}
else
{
if (!infile)
cout<< "Unable to open file input.txt.\n";
if (!outfile)
cout<< "Unable to open file output.txt.\n";
}
}

void writetitle(ofstream& outfile)
{
outfile<< "Title\n\n";
}
void writeheading(ofstream& outfile)
{
outfile<< "Headings\n\n";
}
void sortsf(snowfall validsf[])
{
snowfall temp;

for (int i; i = validsf[i].getvalidcount(); i++)
for (int j; j = i + 1; j++)
if ((float(validsf[i].getft()) * 12 + validsf[i].getin()) >
(float(validsf[j].getft()) * 12 + validsf[j].getin()))
{
temp = validsf[i];
validsf[i] = validsf[j];
validsf[j] = temp;
}
}
void writevalidsf(snowfall validsf[], ofstream& outfile)
{
for (int i=0; i = validsf[i].getvalidcount(); i++)
validsf[i].writedata(outfile);
}
void writeinvalidsf(snowfall invalidsf[], ofstream& outfile)
{
if (invalidsf[0].getinvalidcount() != 0)
for (int i = 0; i = invalidsf[i].getinvalidcount(); i++)
outfile<< "Invalid amount of snowfall for the date, "
<< invalidsf[i].getdate() << endl;
}

 
Reply With Quote
 
 
 
 
Howard
Guest
Posts: n/a
 
      12-13-2004

What kind of help do you need? You haven't said what problems you are
having. Does it compile? Does it crash? Does it incorrectly print out the
latest football stats (like putting the 49ers in 1st place)???

It's a fair amount of work for someone to simply look at a program and guess
what it is supposed to do, and whether it will actually do that. We really
need more information from you as to what exactly is going wrong before we
can tell you why that might be the case.

-Howard


 
Reply With Quote
 
 
 
 
titan0111@hotmail.com
Guest
Posts: n/a
 
      12-13-2004
This is the error messages I'm getting.

Program4.cpp
C:\Program Files\Microsoft Visual
Studio\MyProjects\Program4\Program4.cpp(146) : error C2660: 'sortsf' :
function does not take 0 parameters
C:\Program Files\Microsoft Visual
Studio\MyProjects\Program4\Program4.cpp(14 : error C2660:
'writevalidsf' : function does not take 1 parameters
C:\Program Files\Microsoft Visual
Studio\MyProjects\Program4\Program4.cpp(149) : error C2660:
'writeinvalidsf' : function does not take 1 parameters
Error executing cl.exe.

Program4.exe - 3 error(s), 0 warning(s)

when I click on the error messge, it brings me to this line on the
source code.

sortsf(validsf);
writeheadings(outfile);
writevalidsf(validsf, outfile);
writeinvalidsf(invalidsf, outfile);
validsf[i].writetotalsf(outfile);

 
Reply With Quote
 
Andre Kostur
Guest
Posts: n/a
 
      12-13-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in news:1102958364.558876.130680
@z14g2000cwz.googlegroups.com:

> This is the error messages I'm getting.
>
> Program4.cpp
> C:\Program Files\Microsoft Visual
> Studio\MyProjects\Program4\Program4.cpp(146) : error C2660: 'sortsf' :
> function does not take 0 parameters
> C:\Program Files\Microsoft Visual
> Studio\MyProjects\Program4\Program4.cpp(14 : error C2660:
> 'writevalidsf' : function does not take 1 parameters
> C:\Program Files\Microsoft Visual
> Studio\MyProjects\Program4\Program4.cpp(149) : error C2660:
> 'writeinvalidsf' : function does not take 1 parameters
> Error executing cl.exe.
>
> Program4.exe - 3 error(s), 0 warning(s)
>
> when I click on the error messge, it brings me to this line on the
> source code.
>
> sortsf(validsf);
> writeheadings(outfile);
> writevalidsf(validsf, outfile);
> writeinvalidsf(invalidsf, outfile);
> validsf[i].writetotalsf(outfile);
>


Oh my. Please tell me that you at least indent your code? Also, you may
wish to take up the practice of writing small pieces of code _first_, see
if they compile, then add more (ie: incremental development). Start
with:

int main()
{
}

then compile.

Then add the basic frame of your snowfall class (ie: an empty class named
snowfall), and compile. Repeat in small steps until you get a complete
program. As you gain experience, these small steps may get larger.
Indentation of your code is there for your comprehension of your own code
(and other people trying to comprehend your code....).

A couple things to note:

1) void main() is non-standard. use "int main()".
2) If you write your extra functions before your main function, you have
no need to forward-declare them. Looking at sortsf in particular, you
declare it in main to take an object of type snowfall by value, you later
call it without passing a parameter at all, and finally define it taking
an array of snowfall. Make up your mind.....
3) With a quick glance it looks like you're doing something similar with
the other functions too.
 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      12-13-2004

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> This is the error messages I'm getting.
>
> Program4.cpp
> C:\Program Files\Microsoft Visual
> Studio\MyProjects\Program4\Program4.cpp(146) : error C2660: 'sortsf' :
> function does not take 0 parameters
> C:\Program Files\Microsoft Visual
> Studio\MyProjects\Program4\Program4.cpp(14 : error C2660:
> 'writevalidsf' : function does not take 1 parameters
> C:\Program Files\Microsoft Visual
> Studio\MyProjects\Program4\Program4.cpp(149) : error C2660:
> 'writeinvalidsf' : function does not take 1 parameters
> Error executing cl.exe.
>
> Program4.exe - 3 error(s), 0 warning(s)


These error messages are imo very clear: You've passed the
wrong number of arguments when calling these functions.
Also, your prototypes are wrong.

The prototypes from your originial post:

void sortsf(snowfall); /* requires one argument */
void writevalidsf(snowfall, ofstream&); /* requires two arguments */
void writeinvalidsf(snowfall, ofstream&); /* requires two arguments */

You also have other problems. The actual function definitions:


void sortsf(snowfall validsf[])
{
/* etc */
}

The prototype above does not match this function's signature.
The number of parameters matches, but the type is wrong.
'snowfall' and 'snowfall[]' are not the same type.

void writevalidsf(snowfall validsf[], ofstream& outfile)
{
/* etc */
}

The prototype above does not match this function's signature.
The number of parameters matches, but the type of the first one
is wrong. 'snowfall' and 'snowfall[]' are not the same type.

void writeinvalidsf(snowfall invalidsf[], ofstream& outfile)
{
/* etc */
}

The prototype above does not match this function's signature.
The number of parameters matches, but the type of the first one
is wrong. 'snowfall' and 'snowfall[]' are not the same type.

Your calls to these functions in 'main()':

sortsf(); /* no argument given */
writevalidsf(outfile); /* only one argument given */
writeinvalidsf(outfile); /* only one argument given */


>
> when I click on the error messge, it brings me to this line on the
> source code.
>
> sortsf(validsf);


Wrong number of arguments.

> writeheadings(outfile);
> writevalidsf(validsf, outfile);


Wrong number of arguments.

> writeinvalidsf(invalidsf, outfile);


Wrong number of arguments.

> validsf[i].writetotalsf(outfile);


Fix your prototypes, and provide the correct number of arguments
when calling your functions.

Notes:

1. Note that 'main()' is required to have a return type of 'int'.
Not 'void', or any other type, but 'int'. Only.

2. And finally, when you post code here, please use indentation.
Without, your code is not easy to read.

3. I recommend you consider replacing your arrays with containers
which are more flexible and much less error prone.

HTH,
-Mike


 
Reply With Quote
 
titan0111@hotmail.com
Guest
Posts: n/a
 
      12-13-2004
Thank you.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
routing problems with multiple T1s - I know whats wrong but dont know how to fix it Jason Cisco 5 03-10-2006 01:03 AM
"Microsoft Certification - It's how they know you know" MatrixVic MCSD 0 02-03-2006 02:52 AM
ISAKMP NAT problem (I know it can be done but don't know how) Rogier Mulder Cisco 1 01-13-2005 08:48 PM
I know, I know, I don't know Andries Perl Misc 3 04-23-2004 02:17 AM
Don know Perl, don't know what's broke - re - type1inst!! DP Perl 0 07-17-2003 10:22 PM



Advertisments