so i made this simple program to learn about structures and pointers and i declared 1 variable a char but when i tried to make it equal a letter or word i got an error so i had to put it in as a number. id really like it to be able to display a word. how would i do this. thanks. heres my program:
Code:#include <iostream> using namespace std; struct band { int age; char instrument; }; int main () { int a; int b; cout<< "this program lets you learn about the band members age and instruments.\n"; cout<< "\n"; cout<< "for instruments:\n"; cout<< "1 = Singer\n"; cout<< "2 = Guitar\n"; cout<< "3 = Drums\n"; cout<< "\n"; cout<< "press enter to begin\n"; cin.get (); cout<< "pick who you want to know about.\n"; cout<< "1 - Charlie\n"; cout<< "2 - Jake\n"; cout<< "3 - Matt\n"; cout<< "4 - Otis\n"; cin>> a; switch (a){ case 1: cout<< "you picked Charlie!\n"; cout<< "1 - age\n"; cout<< "2 - instrument\n"; cin>> b; band charlie; band *c; charlie.age = 13; charlie.instrument = 1; c = &charlie; if (b == 1) cout<< c->age; if (b == 2) cout<< c->instrument; break; case 2: cout<< "you picked Jake!\n"; cout<< "1 - age\n"; cout<< "2 - instrument\n"; cin>> b; band jake; band *j; jake.age = 13; jake.instrument = 2; j = &jake; if (b == 1) cout<< j->age; if (b == 2) cout<< j->instrument; break; case 3: cout<< "you picked Matt!\n"; cout<< "1 - age\n"; cout<< "2 - instrument\n"; cin>> b; band matt; band *m; matt.age = 14; matt.instrument = 2; m = &matt; if (b == 1) cout<< m->age; if (b == 2) cout<< m->instrument; break; case 4: cout<< "you picked Otis!\n"; cout<< "1 - age\n"; cout<< "2 - instrument\n"; cin>> b; band otis; band *o; otis.age = 13; otis.instrument = 3; o = &otis; if (b == 1) cout<< o->age; if (b == 2) cout<< o->instrument; break; } cin.get (); }



LinkBack URL
About LinkBacks



