473,464 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

If statement discussion

4 New Member
Hey I was wondering about how you go about designing a IF statement that will use a range of values and if it was out of those range of values, e.g if it was a negative or if it exceeded a certain number, how do i go about creating a IF statement that follows these guidelines.

I have created a IF statement but it only accounts for 1 variable/value at a time and I would like to created a range of variables to be used e.g. 0 - 23953.

if (Download == 1)
{
cout << "1 megabytes downloaded" << endl;
}
else if (Download == 2)
{
cout << "2 megabytes downloaded" << endl;
}
else if (Download == 3)
{
cout << "3 megabytes downloaded" << endl;

I would like to make it so it goes from (1 - 10000)
If it is below 0 it poses a Error and the program closes or If it exceeds 10000 it poses a error and closes, and if any value is entered between 0 - 10000 it displays it on the screen perfectly without creating an error as the appropriate values are used.

Thanks Casey
Apr 6 '07 #1
4 1430
casey2007
4 New Member
Oh sorry I didnt post what compiler im using:

Im using Microsoft Visual Studios.NET 2003 C++
Apr 6 '07 #2
Ganon11
3,652 Recognized Expert Specialist
So basically, you want to see if Download is between 0 and 10000 (for example) instead of 1, or 2, or 3...etc.

An if... statement requires a boolean expression. == is just one of several operators that evaluates to a boolean value. Others include < (less than), > (greater than), != (does not equal), <= (less than or equal to), and >= (greater than or equal to).

Using these, you can check if Download is greater than 0. Now, this will give you an infinite amount of values, so you will have to also check if Download is less than 10000. To combine two or more boolean 'checks', you can use && (and) or || (or). Each is an operator that works on two boolean values - and requires both values to be true, and or requires only one value to be true.

Can you write the if...statements for what you need now?
Apr 6 '07 #3
casey2007
4 New Member
So basically, you want to see if Download is between 0 and 10000 (for example) instead of 1, or 2, or 3...etc.

An if... statement requires a boolean expression. == is just one of several operators that evaluates to a boolean value. Others include < (less than), > (greater than), != (does not equal), <= (less than or equal to), and >= (greater than or equal to).

Using these, you can check if Download is greater than 0. Now, this will give you an infinite amount of values, so you will have to also check if Download is less than 10000. To combine two or more boolean 'checks', you can use && (and) or || (or). Each is an operator that works on two boolean values - and requires both values to be true, and or requires only one value to be true.

Can you write the if...statements for what you need now?
Yes thankyou very much Ganon11 for your helpful information :).
Casey
Apr 9 '07 #4
Ganon11
3,652 Recognized Expert Specialist
Glad to help out!
Apr 9 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Rajat Katyal | last post by:
Hi: In postgres documentation its written that if we execute query as PERFORM query inside our stored procedure; then the special variable FOUND is set totrue if the query produced at least one...
35
by: Thierry Loiseau | last post by:
Hello all, and Happy end year 2005 ! Well, I would like to obtain a list of all JavaScript var statement, With "for...in" perharps ? That is bellow my recent test here, but the problem is...
18
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
28
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions!...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
17
by: djc | last post by:
I got great info on related question previously. This link <http://www.yoda.arachsys.com/csharp/threads/volatility.shtml> from Brian Gideon was especially informative. 1) the lock statement does...
22
by: John | last post by:
Hi Folks, I'm experimenting a little with creating a custom CEdit control so that I can decide on what the user is allowed to type into the control. I started off only allowing floating point...
23
by: Tony Johansson | last post by:
Hello! I just wonder what is the point of having the reader variable declared as TextReader in the snippet below.. Is it because of using the polymorfism on the reader variable perhaps. using...
12
by: Earl Partridge | last post by:
I just downloaded this VB Express. I need a little help in understanding the request for database data, that is the format/syntax compared to an SQL statement. In my SQL I would use a select...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.