Welcome to Dream.In.Code
Click Here
Getting C++ Help is Easy!

Join 117,608 C++ Programmers for FREE! Ask your question and get quick answers from experts. There are 2,442 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



creating an instance of RGB

 
Reply to this topicStart new topic

creating an instance of RGB, create one instance (i don't know what i did wrong)

passionfruit
post 20 Jul, 2008 - 02:42 PM
Post #1


New D.I.C Head

*
Joined: 19 Jul, 2008
Posts: 4

i had to create one instance of RGB, with values (r,g,cool.gif 255,255,255;

this is the coding i created, however i have errors and i don't know why
please help.

cpp
#include<iostream>
#include<string>
using namespace std;

struct RGB
{
int red;
int green;
int blue;
};
void main ()
{
RGB = {"255","255","255"};
cout<<red<<endl;
cout<<green<<endl;
cout<<blue<<endl;
}

Mod edit: Please code.gif
Thanks, gabehabe smile.gif

This post has been edited by gabehabe: 21 Jul, 2008 - 01:52 AM
User is offlineProfile CardPM

Go to the top of the page


marcells23
post 20 Jul, 2008 - 04:27 PM
Post #2


D.I.C Head

Group Icon
Joined: 22 Aug, 2007
Posts: 124



Thanked 2 times

Dream Kudos: 125
My Contributions


This should do what you are looking for.

CODE


#include<iostream>
#include<string>
using namespace std;

struct RGB
{
int red;
int green;
int blue;
};
int main(void)
{

RGB rgb = {255,255,255};//you have to declare the struct as type RGB. also int values dont need quotations

//Then you can reference each of the variables like so...
cout<<rgb.red<<endl;
cout<<rgb.green<<endl;
cout<<rgb.blue<<endl;

return 0;
}
User is offlineProfile CardPM

Go to the top of the page

passionfruit
post 20 Jul, 2008 - 04:37 PM
Post #3


New D.I.C Head

*
Joined: 19 Jul, 2008
Posts: 4

QUOTE(marcells23 @ 20 Jul, 2008 - 04:27 PM) *

This should do what you are looking for.

CODE


#include<iostream>
#include<string>
using namespace std;

struct RGB
{
int red;
int green;
int blue;
};
int main(void)
{

RGB rgb = {255,255,255};//you have to declare the struct as type RGB. also int values dont need quotations

//Then you can reference each of the variables like so...
cout<<rgb.red<<endl;
cout<<rgb.green<<endl;
cout<<rgb.blue<<endl;

return 0;
}




QUOTE(passionfruit @ 20 Jul, 2008 - 04:36 PM) *

QUOTE(marcells23 @ 20 Jul, 2008 - 04:27 PM) *

This should do what you are looking for.

CODE


#include<iostream>
#include<string>
using namespace std;

struct RGB
{
int red;
int green;
int blue;
};
int main(void)
{

RGB rgb = {255,255,255};//you have to declare the struct as type RGB. also int values dont need quotations

//Then you can reference each of the variables like so...
cout<<rgb.red<<endl;
cout<<rgb.green<<endl;
cout<<rgb.blue<<endl;

return 0;
}






thank you!!!
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 10/7/08 11:36PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month