C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 9th, 2006, 06:31 AM
Zephyrus Zephyrus is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: Netherland
Posts: 3 Zephyrus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 38 sec
Reputation Power: 0
Littel problem

Hey, I'm making for my study my first C++ program and I have a program whitch a if statement.

......
cin >> jaar;
if ( (jaar < 1900) || (jaar > 2100) );
{
cout << "Dit jaartal is ongeldig. Toegang Geweigerd. \n";
return 0;
}
.....
this is the statement waht is troubling me.
When I enter 1987 for the integer the if statement is still activate. I want that the program ignore the if statement when the integer "jaar" is between the value 1900 and 2100.
But it doesn't work. Can somebody tell me waht I doing wrong?

Reply With Quote
  #2  
Old September 9th, 2006, 06:46 AM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 19 m 11 sec
Reputation Power: 3
Hi,
I didn't quite understand what do you want to say?Please elaborate!

Costas

Reply With Quote
  #3  
Old September 9th, 2006, 07:39 AM
Zephyrus Zephyrus is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: Netherland
Posts: 3 Zephyrus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 38 sec
Reputation Power: 0
what I wanted to say is,

1. I have a integer called jaar. (dutch word for year but oke )
2. when you enter a value for "jaar" that is < 1900 or > 2100 the program will preform
cout << "Dit jaartal is ongeldig. Toegang Geweigerd. \n";
return 0;
But when the value entered for "jaar" is 1900 >= jaar or 2100 <= jaar. the program must ignore the If-statement. But the problem I have that for wahtever value I enter the program runs
cout << "Dit jaartal is ongeldig. Toegang Geweigerd. \n";
return 0;

My question is how can I fix that.

Reply With Quote
  #4  
Old September 9th, 2006, 08:44 AM
Paul820 Paul820 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Location: United Kingdom
Posts: 346 Paul820 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 14 h 14 m 58 sec
Reputation Power: 3
You need an else:
else
{
cout << "Whatever, here";
}

you have your return 0 inside the if statement. Put that at the end of the program, should be the last thing.

Reply With Quote
  #5  
Old September 9th, 2006, 08:53 AM
Zephyrus Zephyrus is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: Netherland
Posts: 3 Zephyrus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 38 sec
Reputation Power: 0
cin >> jaar;
if ( (jaar < 1900) || (jaar > 2100) );
{
cout << "Dit jaartal is ongeldig. Toegang Geweigerd. \n";
return 1;
}
else
{
cout << " ";
}

when I put a else with a random command my compiler gives the error C2181: illegal else without matching if. What is the problem with that error?

Reply With Quote
  #6  
Old September 9th, 2006, 11:27 AM
ubergeek ubergeek is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2005
Posts: 600 ubergeek User rank is Private First Class (20 - 50 Reputation Level)ubergeek User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 27 sec
Reputation Power: 4
Send a message via AIM to ubergeek
There shouldn't be a ; after the if condition. What the program says is: If jaar < 1900 or jaar > 2100 -- do nothing (since the semicolon's there). Then, cout and return. So take out the semicolon.

Reply With Quote
  #7  
Old September 9th, 2006, 02:27 PM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 19 m 11 sec
Reputation Power: 3
Yes, ubergeek is right; you don't put ; at the end of any condition. Why I didn't see it at first time.

Reply With Quote
  #8  
Old September 9th, 2006, 02:59 PM
ubergeek ubergeek is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2005
Posts: 600 ubergeek User rank is Private First Class (20 - 50 Reputation Level)ubergeek User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 27 sec
Reputation Power: 4
Send a message via AIM to ubergeek
Yeah, same here, costas -- a very hard error to catch. I didn't see it until I saw the error C2181 above.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Littel problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT