Help with static cast
Aug 3, 2014 at 12:55am UTC
I'm trying to learn how to use static cast. I need help understanding why my code isn't working when I try to create a while loop changing a char value to a int value, for use in comparing.
Maybe the code will just explain better than I can
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
do
39 {
40
41
42 cout << "What's your major? " << endl; // get user major
43 cin.get (declare_m, MAJOR,'\n' );
44 declare_m[0] = toupper(declare_m[0]);
45 cin.ignore(100,'\n' );
46
47 int len2 = strlen(declare_m); //capitalize major even strings
48 for (int i = 1; i < len2; ++i)
49 {
50 if ( declare_m[i] == ' ' )
51 declare_m[i+1] = toupper(declare_m[i+1]);
52 }
53 } while (dynamic_cast <int >(declare_m) > MAJOR);
54
55 if (strcmp(declare_m,"Computer Science" ) == 0)
56 cout << "Your major is " << declare_m << " fellow nerd!!" << endl;
57 else
58
59 cout << "Your major is: " << declare_m << endl;
60
61 return 0;
62 }
Aug 3, 2014 at 1:45am UTC
What is this line of code supposed to be doing?
53 54
while (dynamic_cast <int >(declare_m) > MAJOR);
...
What do you expect to get by casting a string to int?
Did this code even compile?
Last edited on Aug 3, 2014 at 1:49am UTC
Aug 3, 2014 at 2:04am UTC
That's why I'm asking other people. It didn't I was just trying something random.
Topic archived. No new replies allowed.