| | |
how to use pointers in struct
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
C++ Syntax (Toggle Plain Text)
#include<stdio.h> #include<iostream.h> struct fruits { int apple; int banana; int orange; int jackfruit; } fruit; int shape; int color; int texture; void main() { struct fruits *pfruit; pfruit=&fruit; cout<<"Enter the number of your choice for shape: [0] round/ [1] oblong"<<endl; cin>>inputFruits(); cout<<"Enter the number of your choice for color: [0] green/ [1] yellow/ [2] red/ [3] orange"<<endl; cin>>inputFruits(); cout<<"Enter the number of your choice for texture: [0] smooth/ [1] rough"<<endl; cin>>inputFruits(); } void inputFruits(struct fruits *pfruit) { if(shape==0) { cout<<"round"<<endl; cin>>shape; } else { cout<<"oblong"<<endl; cin>>shape; } if(color==0) { cout<<"green"<<endl; cin>>color; } if(color==1) { cout<<"yellow"<<endl; cin>>color; } if(color==2) { cout<<"red"<<endl; cin>>color; } if(color==3) { cout<<"orange"<<endl; cin>>color; } if(texture==0) { cout<<"smooth"<<endl; cin>>texture; } else { cout<<"rough"<<endl; cin>>texture; } } void identifyFruits(struct fruits *pfruit) { if(shape==0) { if(color==2) { if(texture==0) { cout<<"Apple"<<endl; cin>>pfruit->apple; }}} if(shape==1) { if(color==1) { if(texture==0) { cout<<"Banana"<<endl; cin>>pfruit->banana; }}} if(shape==0) { if(color==3) { if(texture==0) { cout<<"Orange"<<endl; cin>>pfruit->orange; }}} if(shape==1) { if(color==0) { if(texture==1) { cout<<"Jackfruit"<<endl; cin>>pfruit->jackfruit; }}} }
Sorry..
In this program you will enter the number of your choice if 0 (round) or 1 (oblong) for the shape.
For the color 0(green), 1(yellow), 2(red), 3(orange)
For the texture 0(smooth) or 1(rough).
It will identify the type of fruit..
example if you input 0 for shape, 2 for color, and 0 for texture it will tell you that fruit is an apple
In this program you will enter the number of your choice if 0 (round) or 1 (oblong) for the shape.
For the color 0(green), 1(yellow), 2(red), 3(orange)
For the texture 0(smooth) or 1(rough).
It will identify the type of fruit..
example if you input 0 for shape, 2 for color, and 0 for texture it will tell you that fruit is an apple
>can someone teach me how to use pointer in this program??i don't know if what i did in this program is correct. can you tell me how to use pointers here.thanks!
Please Be specific.
This is not a teaching classroom dear. You must read your text book and come to us with very specific questions.
We, can tell you how to use pointers but how the hell are we suppose to explain you the whole program. Do you think it is feasible?
Secondly, DO NOT USE VOID MAIN() http://cppdb.blogspot.com/2009/02/sh...t-main-or.html
use
And thirdly, The program contains lot of (trivial) errors. We are not going to debug them for you. For your curiosity, there's a error in the
So, please correct the errors and read the book. Then asks what is troubling you.
Please Be specific.
This is not a teaching classroom dear. You must read your text book and come to us with very specific questions.
We, can tell you how to use pointers but how the hell are we suppose to explain you the whole program. Do you think it is feasible?
Secondly, DO NOT USE VOID MAIN() http://cppdb.blogspot.com/2009/02/sh...t-main-or.html
use
#include<iostream> and #include<cstdio> Use a new compiler not a old one(http://cppdb.blogspot.com/2008/10/wh...use-old-c.html)And thirdly, The program contains lot of (trivial) errors. We are not going to debug them for you. For your curiosity, there's a error in the
cin>>inputfruits() You cannot cin to function.So, please correct the errors and read the book. Then asks what is troubling you.
Last edited by siddhant3s; Mar 12th, 2009 at 9:03 pm.
Siddhant Sanyam
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
•
•
•
•
...
Please Be specific.
...
Secondly, DO NOT USE VOID MAIN() http://cppdb.blogspot.com/2009/02/sh...t-main-or.html
use#include<iostream>and#include<cstdio>Use a new compiler not a old one
(http://cppdb.blogspot.com/2008/10/wh...use-old-c.html)
...
![]() |
Similar Threads
- C++ pointer/Struct help please (C++)
- Pointers to struct (C++)
- Converting Struct to class lost with pointers (C++)
Other Threads in the C++ Forum
- Previous Thread: Need help with visual C++
- Next Thread: how to do string input?
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






