Weird output that's not expected

Afternoon gang, I tried creating a sample program for learning purposes and failed. I'm trying to have multiple options for an input and this is what I developed.
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
using namespace std;

class c1
        {
            public:
            void customerinput()
            {

            char icecream;
            cout<<"Please enter what flavor you like (Chocolate Vanilla, Mint)"<<endl;
            cin>>icecream;
            if (icecream= 'Vanilla')
 {

                char sizt;
                cout<<"What size would you like (large small medium)"<<endl;
                cin>> sizt;
                if (sizt = 'large')

                {
                    cout<<"You ordered a large"<<endl;

                }
                else if (sizt= 'small')
                {
                    cout<<"You ordered a small"<<endl;


                }
                else if (sizt = 'Medium')
                {

                    cout<<"You ordered a medium"<<endl;
                                   }
            }
            }

        };

int main()
{
    c1 jo;
    jo.customerinput();
    return 0;
}


When I run this through, it will not run or process the if statment within the if statment, it will just print out the first script print without you stating what size wanted. What's wrong with this and why won't it process the if/else if statements within the main if statment?

Thank you in advance.
one of the things that is hard to get accustomed to in c++ are these two operators:

=
==

the first one is called the "assignment" operator, and is used to assign a value to a variable. When people first encounter this operator, they assume "equals to" because of math, but its simply not the case here.

the second one is the "equals to" operator and is used when you want to check if two values are equal to each other.

You'll want to check your if statements now.
I tried using both "=" and "==" and did not get it to run as it should, please note this isn't homework (I'm learning c++ on my own as a first language) or the original text, I just wrote it in this form to see if I could get it to work prior to sending it on here. It still doesn't work as planned, I cannot choose a size after entering in the flavor.
You are using chars. Chars hold a single character, nothing more. Use std::string if you want to compare them to a literal string like "Vanilla".
how would a std::string look? Sorry I'm new at programming and learning from home. It's not that I want to compare, I want a sub preference for the size of the flavor.
In that case for now just stick to chars, not strings. Like I said a char only holds a single character, so instead of comparing one to a word like 'vanilla' you compare it to 'v' or 'V'.

And like pogrady said, you need to use == instead of =.

icecream = 'v' makes icecream equal to 'v'

icecream == 'v' compares the content of icecream to the character 'v'

See the difference?
Ok that makes sense to as of why it wouldn't run, when I had the == set to one variable, it would print but I figured it would still work no matter the variable count as long as the variable entered matched the variable possibilities (if/else if...) Anyway I can enter in the full variable 'medium' instead of 'm'?
Here's a small program demonstrating how to do this with strings:

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
#include <string>     // for std::string
#include <algorithm>  // for std::transform
#include <cctype>     // for std::tolower

const std::string flavors[] = 
{
    "Chocolate",
    "Vanilla",
    "Gumball",
    "Turkey",
    "Wild Nuts"
};

const std::string sizes[] =
{
    "Small",
    "Medium",
    "Large",
    "Super Gigantic"
};

// a common method of getting the number of elements in an array (in
// the scope in which the array is defined) is to take the overall
// size of the array and divide it by the size of one of it's elements.
const unsigned num_flavors = sizeof(flavors) / sizeof(flavors[0]) ;
const unsigned num_sizes   = sizeof(sizes)   / sizeof(sizes[0])   ;

// just to shorten things up a bit for posting:
typedef const std::string const_string ;

// returns true if to_check occurs in labels.
bool check_against( const_string to_check, const_string labels[], unsigned elements ) ;

// convenience function for displaying the list of flavors/sizes
void display(std::ostream & out,  const_string labels[], unsigned elements, 
             const_string title, const_string prompt) ;

int main()
{
    std::string flavor ;
    do
    {
        display( std::cout, flavors, num_flavors, 
            "Flavors are:", "What flavor would you like?" ) ;
        std::getline(std::cin, flavor);
    } while (!check_against(flavor, flavors, num_flavors)) ;

    std::string size ;
    do
    {
        display( std::cout, sizes, num_sizes, 
            "Sizes are:", "What size would you like?") ;
        std::getline(std::cin, size) ;
    } while ( !check_against(size, sizes, num_sizes) ) ;

    std::cout << "You ordered a " << size << ' ' << flavor << " icecream.\n" ;
}

// another convenience function:  returns a lower cases version
// of the string supplied.
std::string lower_case( const_string s )
{
    std::string t = s ;
    std::transform(t.begin(), t.end(), t.begin(), std::tolower) ;
    return t ;
}

bool check_against( const_string to_check, const_string labels[], unsigned elements )
{
    std::string check_me = lower_case(to_check) ;

    for ( unsigned i=0; i<elements; ++i )
    {
        if ( check_me == lower_case(labels[i]) )
            return true ;
    }

    return false ;
}

void display(std::ostream & out, const_string labels[], unsigned num_labels, 
             const_string title, const_string prompt )
{
    out << '\n' << title << '\n' ;
    for ( unsigned i=0;  i<num_labels;  ++i )
        out << '\t' << labels[i] << '\n' ;
    out << prompt << '\n' ;
}


Links that may be useful to understand this code:
http://www.cplusplus.com/reference/algorithm/transform/
http://www.cplusplus.com/reference/clibrary/cctype/tolower/
http://www.cplusplus.com/reference/string/string/

If you have questions, feel free to ask. Note: Normally one would present menus with numbered items in a console environment and ask the user for the number associated with the item they want, which greatly simplifies input validation -- this is not the recommended way of presenting a list of items to a user.
Thanks so much for the code writing, that's exactly what I wanted. This looks like it will take some time for me to learn.
Topic archived. No new replies allowed.