d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > New To This > Switch Statement Syntax
Prev12
Add Reply New Topic New Poll
Member
Posts: 14,631
Joined: Sep 14 2006
Gold: 575.56
Jul 1 2015 09:43pm
Quote (bentherdonethat @ Jun 28 2015 08:03pm)
Are you missing something in each of those cout statements that would insert the newline and flush the buffer?

cout << message << endl;


no it's just a practice problem not actual code
and if i wanted an endline in there anyway i'ld probably put it after the entire switch was done yaknow, save myself from typin it every time.

also, i'm all about "\n"
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Jul 2 2015 07:07pm
Quote (Ideophobe @ Jul 1 2015 10:32pm)
ye took up a hobby, hope ya dont mind me swingin by if i got a quick question every now and again.
took a couple semesters of oracle to build a database for the company, now i wanna integrate that with a gui sales suite figured c++ was a good place to start


it can be addicting
Member
Posts: 14,631
Joined: Sep 14 2006
Gold: 575.56
Jul 3 2015 08:12pm
don't think that's possible in my case, anways learning loop control this week, I've been craving it since week 1.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jul 3 2015 08:55pm
i see you removed the snarky comments from your reply. there's no need for that attitude when someone's trying to help you.

my intention wasn't to give you obscure links. the documentation explained your problem. i hope after you got it working that you went back to the documentation to try and understand it. in case you didn't:

Code
switch ( condition ) statement
case constant_expression : statement


Quote
constant_expression - a constant expression of the same type as the type of condition after conversions and integral promotions


in your code:
condition: age
constant_expression: age < 2

your condition age is of some integer type. your constant_expression age < 2 is a boolean type. the documentation explains that they must both be the same type, which is why you cannot use booleans.

This post was edited by carteblanche on Jul 3 2015 08:58pm
Member
Posts: 14,631
Joined: Sep 14 2006
Gold: 575.56
Jul 4 2015 12:00am
Quote (carteblanche @ Jul 3 2015 08:55pm)
i see you removed the snarky comments from your reply. there's no need for that attitude when someone's trying to help you.

my intention wasn't to give you obscure links. the documentation explained your problem. i hope after you got it working that you went back to the documentation to try and understand it. in case you didn't:

Code
switch ( condition ) statement
case constant_expression : statement




in your code:
condition: age
constant_expression: age < 2

your condition age is of some integer type. your constant_expression age < 2 is a boolean type. the documentation explains that they must both be the same type, which is why you cannot use booleans.


its whatever man i figured it out. class is online, i misunderstood something. its why i came here

i just got a bit irritated reading the first few lines of your link

which says
Code
attr(C++11) - any number of attributes
condition - any expression of integral or enumeration type, or of a class type contextually implicitly convertible to an integral or enumeration type, or a declaration of a single non-array variable of such type with a brace-or-equals initializer.
statement - any statement (typically a compound statement). case: and default: labels are permitted in statement and break; statement has special meaning.

and ild never heard of attr(c++11) and i'm just like wtf is all this vocabulary, i thought i understood what a condition is, now i dont even know what i dont know wtf is going on. and i just spent like 3 hours doing practice problems, just wanna figure it out why it wouldn't work and move on.

anyway now i just think of switch as a literal switch, like a switchboard between single values each case is 1 thing only. i've gotten linked to that site a few times with random questions and it doesnt seem very novice friendly even though it has alot of beginner information

This post was edited by Ideophobe on Jul 4 2015 12:02am
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jul 4 2015 07:57am
Quote (Ideophobe @ Jul 4 2015 02:00am)
its whatever man i figured it out. class is online, i misunderstood something. its why i came here

i just got a bit irritated reading the first few lines of your link

which says
Code
attr(C++11) - any number of attributes
condition - any expression of integral or enumeration type, or of a class type contextually implicitly convertible to an integral or enumeration type, or a declaration of a single non-array variable of such type with a brace-or-equals initializer.
statement - any statement (typically a compound statement). case: and default: labels are permitted in statement and break; statement has special meaning.

and ild never heard of attr(c++11) and i'm just like wtf is all this vocabulary, i thought i understood what a condition is, now i dont even know what i dont know wtf is going on. and i just spent like 3 hours doing practice problems, just wanna figure it out why it wouldn't work and move on.

anyway now i just think of switch as a literal switch, like a switchboard between single values each case is 1 thing only. i've gotten linked to that site a few times with random questions and it doesnt seem very novice friendly even though it has alot of beginner information


the c++ language uses a compiler to compile down your high level code to native code. the real magic happens in the compiler. one might think there's only one compiler, and that defines what c++ is. that's actually not correct. c++ is defined by a spec. anyone and their mother can write a c++ compiler as long as it adheres to the spec. the notation of c++11 is referring to the c++11 specification which came out a few years ago. it indicates that the attr might not be available if you're using an old compiler or compiling to an older specification.

you studied oracle for a few semesters. have you looked at oracle's documentation? it gets really annoying. i know generic sql, so when i wanna look up the oracle syntax for something, i have to google it. this is the shit that pops up when i try to find out how to create a table in oracle:

Code
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
(create_definition,...)
[table_options]
[partition_options]

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
[(create_definition,...)]
[table_options]
[partition_options]
select_statement

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
{ LIKE old_tbl_name | (LIKE old_tbl_name) }

create_definition:
col_name column_definition
| [CONSTRAINT [symbol]] PRIMARY KEY [index_type] (index_col_name,...)
[index_option] ...
| {INDEX|KEY} [index_name] [index_type] (index_col_name,...)
[index_option] ...
| [CONSTRAINT [symbol]] UNIQUE [INDEX|KEY]
[index_name] [index_type] (index_col_name,...)
[index_option] ...
| {FULLTEXT|SPATIAL} [INDEX|KEY] [index_name] (index_col_name,...)
[index_option] ...
| [CONSTRAINT [symbol]] FOREIGN KEY
[index_name] (index_col_name,...) reference_definition
| CHECK (expr)

column_definition:
data_type [NOT NULL | NULL] [DEFAULT default_value]
[AUTO_INCREMENT] [UNIQUE [KEY] | [PRIMARY] KEY]
[COMMENT 'string']
[COLUMN_FORMAT {FIXED|DYNAMIC|DEFAULT}]
[STORAGE {DISK|MEMORY|DEFAULT}]
[reference_definition]

data_type:
BIT[(length)]
| TINYINT[(length)] [UNSIGNED] [ZEROFILL]
| SMALLINT[(length)] [UNSIGNED] [ZEROFILL]
| MEDIUMINT[(length)] [UNSIGNED] [ZEROFILL]
| INT[(length)] [UNSIGNED] [ZEROFILL]
| INTEGER[(length)] [UNSIGNED] [ZEROFILL]
| BIGINT[(length)] [UNSIGNED] [ZEROFILL]
| REAL[(length,decimals)] [UNSIGNED] [ZEROFILL]
| DOUBLE[(length,decimals)] [UNSIGNED] [ZEROFILL]
| FLOAT[(length,decimals)] [UNSIGNED] [ZEROFILL]
| DECIMAL[(length[,decimals])] [UNSIGNED] [ZEROFILL]
| NUMERIC[(length[,decimals])] [UNSIGNED] [ZEROFILL]
| DATE
| TIME
| TIMESTAMP
| DATETIME
| YEAR
| CHAR[(length)] [BINARY]
[CHARACTER SET charset_name] [COLLATE collation_name]
| VARCHAR(length) [BINARY]
[CHARACTER SET charset_name] [COLLATE collation_name]
| BINARY[(length)]
| VARBINARY(length)
| TINYBLOB
| BLOB
| MEDIUMBLOB
| LONGBLOB
| TINYTEXT [BINARY]
[CHARACTER SET charset_name] [COLLATE collation_name]
| TEXT [BINARY]
[CHARACTER SET charset_name] [COLLATE collation_name]
| MEDIUMTEXT [BINARY]
[CHARACTER SET charset_name] [COLLATE collation_name]
| LONGTEXT [BINARY]
[CHARACTER SET charset_name] [COLLATE collation_name]
| ENUM(value1,value2,value3,...)
[CHARACTER SET charset_name] [COLLATE collation_name]
| SET(value1,value2,value3,...)
[CHARACTER SET charset_name] [COLLATE collation_name]
| spatial_type

index_col_name:
col_name [(length)] [ASC | DESC]

index_type:
USING {BTREE | HASH}

index_option:
KEY_BLOCK_SIZE [=] value
| index_type
| WITH PARSER parser_name

reference_definition:
REFERENCES tbl_name (index_col_name,...)
[MATCH FULL | MATCH PARTIAL | MATCH SIMPLE]
[ON DELETE reference_option]
[ON UPDATE reference_option]

reference_option:
RESTRICT | CASCADE | SET NULL | NO ACTION

table_options:
table_option [[,] table_option] ...

table_option:
ENGINE [=] engine_name
| AUTO_INCREMENT [=] value
| AVG_ROW_LENGTH [=] value
| [DEFAULT] CHARACTER SET [=] charset_name
| CHECKSUM [=] {0 | 1}
| [DEFAULT] COLLATE [=] collation_name
| COMMENT [=] 'string'
| CONNECTION [=] 'connect_string'
| DATA DIRECTORY [=] 'absolute path to directory'
| DELAY_KEY_WRITE [=] {0 | 1}
| INDEX DIRECTORY [=] 'absolute path to directory'
| INSERT_METHOD [=] { NO | FIRST | LAST }
| KEY_BLOCK_SIZE [=] value
| MAX_ROWS [=] value
| MIN_ROWS [=] value
| PACK_KEYS [=] {0 | 1 | DEFAULT}
| PASSWORD [=] 'string'
| ROW_FORMAT [=] {DEFAULT|DYNAMIC|FIXED|COMPRESSED|REDUNDANT|COMPACT}
| TABLESPACE tablespace_name [STORAGE {DISK|MEMORY|DEFAULT}]
| UNION [=] (tbl_name[,tbl_name]...)

partition_options:
PARTITION BY
{ [LINEAR] HASH(expr)
| [LINEAR] KEY(column_list)
| RANGE(expr)
| LIST(expr) }
[PARTITIONS num]
[SUBPARTITION BY
{ [LINEAR] HASH(expr)
| [LINEAR] KEY(column_list) }
[SUBPARTITIONS num]
]
[(partition_definition [, partition_definition] ...)]

partition_definition:
PARTITION partition_name
[VALUES
{LESS THAN {(expr) | MAXVALUE}
|
IN (value_list)}]
[[STORAGE] ENGINE [=] engine_name]
[COMMENT [=] 'comment_text' ]
[DATA DIRECTORY [=] 'data_dir']
[INDEX DIRECTORY [=] 'index_dir']
[MAX_ROWS [=] max_number_of_rows]
[MIN_ROWS [=] min_number_of_rows]
[TABLESPACE [=] tablespace_name]
[NODEGROUP [=] node_group_id]
[(subpartition_definition [, subpartition_definition] ...)]

subpartition_definition:
SUBPARTITION logical_name
[[STORAGE] ENGINE [=] engine_name]
[COMMENT [=] 'comment_text' ]
[DATA DIRECTORY [=] 'data_dir']
[INDEX DIRECTORY [=] 'index_dir']
[MAX_ROWS [=] max_number_of_rows]
[MIN_ROWS [=] min_number_of_rows]
[TABLESPACE [=] tablespace_name]
[NODEGROUP [=] node_group_id]

select_statement:
[IGNORE | REPLACE] [AS] SELECT ... (Some valid select statement)


while it gives a lot of info, all i really wanted was an example of the syntax :/
Member
Posts: 14,631
Joined: Sep 14 2006
Gold: 575.56
Jul 4 2015 11:09am
compiler theory now? i'm in cs 110 man

as far as the oracle stuff goes, ya I don't like googling anything that i haven't already learned just to check myself on quickly. I have 2 notebooks full of notes and i got one of those little 5" x 3" notebooks and made myself a little dictionary of syntax. The classes i took were run through "Oracle Academy" so i got used to how they wrote syntax. Pretty much just gotta remember that the [brackets] and the | "or" symbol aren't actually part of the code and you're good.

CREATE TABLE table_name
SELECT * FROM another_table

thats your basic syntax think of the brackets and | thingys like

CREATE TABLE table_name
[you can have create a definition here the syntax for that is below]
[you can adjust the table options here the syntax is below]
[you can partition it here, the syntax is below]
select whatever

when you see something like
data_type [NOT NULL | NULL] [DEFAULT default_value]
it just means you put your type and then you have the additional restrictions you can put after

INT NOT NULL DEFAULT 1
u got your type then you can (if you want) tell it whether it has to be null or not null and you can add a default to it

This post was edited by Ideophobe on Jul 4 2015 11:30am
Go Back To Programming & Development Topic List
Prev12
Add Reply New Topic New Poll