Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 16th, 2006, 1:08 PM   #11
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Bear in mind that switch is not necessarily a substitute for the if/else/elseif type of construct:
Quote:
Originally Posted by MSDN
The C++ switch statement allows selection among multiple sections of code, depending on the value of an expression. The expression enclosed in parentheses, the “controlling expression,” must be of an integral type or of a class type for which there is an unambiguous conversion to integral type.

and

Syntax

case constant-expression : statement

default : statement

The constant-expression in the case label is converted to the type of the controlling expression and is then compared for equality. In a given switch statement, no two constant expressions in case statements can evaluate to the same value.
People often forget this minor detail.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Feb 16th, 2006, 10:12 PM   #12
jobobshishkabob
Programmer
 
Join Date: Jan 2006
Location: Texas
Posts: 36
Rep Power: 0 jobobshishkabob is on a distinguished road
Quote:
Originally Posted by babbling
Do you mean something like this?

if( x == y && x == a && x == b && x == c )
{
  // ...
}
yes kind of....

so basically what i need is that and

if( x != y && x != a && x != b && x != c )
{
  // ...
}

replace the //....

if( x == y && x == a && x == b && x == c )
{
  // put (variable) on a list
}
or
if( x != y && x != a && x != b && x != c )
{
  // ignore (variable)
}


all i need to know is how to place it on a list... after that the next page will be like

cout<<"All contain: \n";
// displays list

two more questions... how to i say "x = whatever"... i know how to say "x = a number" but i need "x = a word"
int x = (10)
cout<<x;
that method only works with numbers, how do i do it with letters

and one more thing... does && mean "and" or "and/or"


Thanks

Last edited by jobobshishkabob; Feb 16th, 2006 at 10:26 PM.
jobobshishkabob is offline   Reply With Quote
Old Feb 16th, 2006, 10:59 PM   #13
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
this guy is so funny ..HAHAHAHAHAHA

quote "Frankly, if you can't express yourself clearly to a human, how do you expect to express yourself clearly to your machine?... "i want to set them all aside in a side in a list." Say that out loud to yourself and see if you "get it." (DaWei)
Eric the Red is offline   Reply With Quote
Old Feb 16th, 2006, 11:10 PM   #14
babbling
Newbie
 
Join Date: Feb 2006
Posts: 11
Rep Power: 0 babbling is on a distinguished road
There are different types of variables. The 'int' variable can only hold integers up to a certain value. Some other types of variables are 'char' and 'float'.

A 'char' variable can hold a single, 8-bit (well, 8-bit on almost all current architectures, anyway) character such as the lower-case letter 'a', upper-case 'A' or the question mark '?' symbol.
Example:
char foo = 'Y';

A 'float' variable can hold irrational numbers like 3.14159 and 2.71828. It has limited precision, but should be enough for most purposes. A 'double' has greater precision.
Example:
float bar = 3.14159;

A 'string' is a class from the C++ standard library that is capable of holding a string of characters, for example, "a word, or even words separated by spaces and punctuation".
Example program using strings:
#include <iostream>
#include <string>
using namespace std;
int main()
{
  string name = "babbling";
  cout << name << endl;
  return 0;
}

Don't use '\n' in C++, because it will not work as expected on all platforms. If you use "endl", it will produce nothing more and nothing less than a new line on all platforms.

I recommend you get a good C++ book, because you have a lot of stuff to learn about. "The C++ Programming Language" by Bjarne Stroustrup isn't a very easy read, but it will make you a better C++ programmer than any other book will. Once you have read and understood the basics, it also becomes easier to read.

Good luck!
babbling is offline   Reply With Quote
Old Feb 16th, 2006, 11:28 PM   #15
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 750
Rep Power: 3 Jimbo is on a distinguished road
Quote:
Originally Posted by babbling
A 'float' variable can hold irrational numbers like 3.14159 and 2.71828.
...
Don't use '\n' in C++, because it will not work as expected on all platforms. If you use "endl", it will produce nothing more and nothing less than a new line on all platforms.
More specifically, doubles and floats hold floating-point values, not just irrational numbers. And endl flushes the stream it is used on, which is a very very minute amount of extra overhead.
Jimbo is offline   Reply With Quote
Old Feb 17th, 2006, 3:14 AM   #16
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 750
Rep Power: 3 Jimbo is on a distinguished road
Oh, and && is just strictly and. Use || for or, which is probably what you want, unless you use !=
Jimbo is offline   Reply With Quote
Old Feb 18th, 2006, 1:23 PM   #17
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by babbling
Don't use '\n' in C++, because it will not work as expected on all platforms. If you use "endl", it will produce nothing more and nothing less than a new line on all platforms.
Don't babble so much and stick to the facts. Like Jimbo said, endl flushes the stream. Jimbo I don't know what you mean by 'strictly and', just to be clear to the others: && is 'logical AND', whereas & is 'bitwise AND'.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:15 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC