473,395 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

something wrong in function, but what?

Hi everyone,
I've tried for a few day to make a function to check out the zipcode. But it
just doens't work. Can someone help me?

In the zipcode, the figures must be larger than 1000 en the charaters may
not be empty, but when the letter kind is "A", "D" of "F" then the zipcode
may be "0000 ".

TI@,
Wen

#include <iostream>
#include <string>
struct Zipcode
{
int cijfer;
char letter[3];
};

int PostcodeContr(int& juist);
using namespace std;

int main()
{
char soort[2];
Zipcode code;
int goed;
cout<<endl;
cin>>code.cijfer;
cin.getline(code.letter,3);
cout<<"soort :"<<endl;
cin>>soort;

PostcodeContr(goed);
cout<<goed;
cin.get();
cin.get();
}

int PostcodeContr(int & juist)
{
Zipcode pcode;
char soort [2];
//1 is right, 2 is wrong.

if(pcode.cijfer > 1000 && strcmp(pcode.letter," ")!=0)
return juist = 1;

//als soort is gelijk aan A of D of F en postcode="0000 "
else if((stricmp(soort, "A") == 0 || stricmp(soort, "D") == 0
|| stricmp(soort, "F") == 0 )
&& pcode.cijfer == 0 && strcmp(pcode.letter," ")==0)
return juist = 1;

else
return juist = 2;

}
Jul 22 '05 #1
3 1345

"Kees Hoogendijk" <ni********@haalditweg-hcopleidingen.nl> wrote in message
news:bs**********@news.cistron.nl...
Hi everyone,
I've tried for a few day to make a function to check out the zipcode. But it just doens't work. Can someone help me?

In the zipcode, the figures must be larger than 1000 en the charaters may
not be empty, but when the letter kind is "A", "D" of "F" then the zipcode may be "0000 ".

TI@,
Wen

#include <iostream>
#include <string>
struct Zipcode
{
int cijfer;
char letter[3];
};

int PostcodeContr(int& juist);
using namespace std;

int main()
{
char soort[2];
Zipcode code;
int goed;
cout<<endl;
cin>>code.cijfer;
cin.getline(code.letter,3);
cout<<"soort :"<<endl;
cin>>soort;

PostcodeContr(goed);
you pass above goed which is an unitialised integer. shouldn't your function
accept a Zipcode?
like:

goed = PostcodeContr(code);

cout<<goed;
cin.get();
cin.get();
}

int PostcodeContr(int & juist) and according to what I suggested, the function should be:

int PostcodeContr(Zipcode & pcode) {
Zipcode pcode; ^^^^^^^^^^^^^^^^ don't need this, you pass in the zipcode
however, the way it was before, you were using an unitialised pcode

I stop here.

char soort [2];
//1 is right, 2 is wrong.

if(pcode.cijfer > 1000 && strcmp(pcode.letter," ")!=0)
return juist = 1;

//als soort is gelijk aan A of D of F en postcode="0000 "
else if((stricmp(soort, "A") == 0 || stricmp(soort, "D") == 0
|| stricmp(soort, "F") == 0 )
&& pcode.cijfer == 0 && strcmp(pcode.letter," ")==0)
return juist = 1;

else
return juist = 2;

}


Dan
Jul 22 '05 #2
Hi Dan,

Thank You Very Much!!
It works now.
Happy New Year!

Wen.

"Dan Cernat" <ce****@dan.com> schreef in bericht
news:vu************@corp.supernews.com...

"Kees Hoogendijk" <ni********@haalditweg-hcopleidingen.nl> wrote in message news:bs**********@news.cistron.nl...
Hi everyone,
I've tried for a few day to make a function to check out the zipcode. But
it
just doens't work. Can someone help me?

In the zipcode, the figures must be larger than 1000 en the charaters
may not be empty, but when the letter kind is "A", "D" of "F" then the

zipcode
may be "0000 ".

TI@,
Wen

#include <iostream>
#include <string>
struct Zipcode
{
int cijfer;
char letter[3];
};

int PostcodeContr(int& juist);
using namespace std;

int main()
{
char soort[2];
Zipcode code;
int goed;
cout<<endl;
cin>>code.cijfer;
cin.getline(code.letter,3);
cout<<"soort :"<<endl;
cin>>soort;

PostcodeContr(goed);


you pass above goed which is an unitialised integer. shouldn't your

function accept a Zipcode?
like:

goed = PostcodeContr(code);

cout<<goed;
cin.get();
cin.get();
}

int PostcodeContr(int & juist)

and according to what I suggested, the function should be:

int PostcodeContr(Zipcode & pcode)
{
Zipcode pcode;

^^^^^^^^^^^^^^^^ don't need this, you pass in the zipcode
however, the way it was before, you were using an unitialised pcode

I stop here.

char soort [2];
//1 is right, 2 is wrong.

if(pcode.cijfer > 1000 && strcmp(pcode.letter," ")!=0)
return juist = 1;

//als soort is gelijk aan A of D of F en postcode="0000 "
else if((stricmp(soort, "A") == 0 || stricmp(soort, "D") == 0
|| stricmp(soort, "F") == 0 )
&& pcode.cijfer == 0 && strcmp(pcode.letter," ")==0)
return juist = 1;

else
return juist = 2;

}


Dan

Jul 22 '05 #3
On Sat, 27 Dec 2003 14:58:22 +0100, Kees Hoogendijk wrote:
#include <iostream>
#include <string>
struct Zipcode
{
int cijfer;
char letter[3];
};

int PostcodeContr(int& juist);
using namespace std;

int main()
{
char soort[2];
Zipcode code;
int goed;
cout<<endl;
cin>>code.cijfer;
cin.getline(code.letter,3);
cout<<"soort :"<<endl;
cin>>soort;


Oopsa, this will read into a two character array, meaning you can store
one character and a terminating zero. Probably not what you want!

Even if you make soort larger ([3]), the user can still enter more than
two characters. Potentially (very high potential) crashing your program.

Why not use std::string? It was designed to get around this kind of
problems. I personally also always read complete lines and only the start
to parse them, so I personally never use << on input streams (except
stringstreams and there I use it often).

Groetjes,
M4

Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: titan0111 | last post by:
#include<iostream> #include<iomanip> #include<cstring> #include<fstream> using namespace std; class snowfall { private: int ft;
6
by: Vandana Rola | last post by:
Hello Everyone, I posted this question earlier under creating Multiple choice quiz. Is it possible to ignore something using javascript. What I am trying to do is creating a multiple answer...
51
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this...
60
by: Dominique Léger | last post by:
Hello guys, I'm kinda new to C, and I'm having a hard time with strings. What I'm trying to do is a simple function that trims spaces & tabs at the beginning of a given string. For example, I...
56
by: maadhuu | last post by:
hello, this is a piece of code ,which is giving an error. #include<stdio.h> int main() { int a =10; void *p = &a; printf("%d ", *p ); //error....why should it //be an error ?can't the...
1
by: Brian Keating EI9FXB | last post by:
Hello there, I've been playing with custom draw and am having a bit of difficulty, Namely the graphics function in this function throws invalid arg exception. Im pretty sure this is correct cause...
1
by: alvarojaviervera | last post by:
Allways I think Firefox was strong, enough ... and so far THE BEST Web- browser (That what I Think) but, now Im fighting with it, may be Im doing something wrong (of course that is what happend to...
9
by: Tiruak | last post by:
Ok, from the title you can probably tell im a beginner to Flash. I'm using CS3, and am trying to create a "menu" to this one webpage. I did 4 animated buttons, but now im having problems making...
34
by: raphfrk | last post by:
This program should copy one file onto the other. It works if I compile it with gcc to a cygwin program. However, if I compile it with the -mno-cygwin option, it doesn't work (this targets native...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.