emergency !!!!!

when i enter the option 1... it will display 2 output the following question... i mean>>>>>>it will be like this..
> enter your name:enter your diameter:
how can i make it separately?

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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include <iostream>
#include <windows.h>
#include <cstdlib>
#include <string>
#include <fstream>

using namespace std;

void welcome ()
{
	cout << string(79,'=') << endl;
	cout << "|" << string (77,' ') << "|" << endl;
	cout << "|" << string (77,' ') << "|" << endl;
	cout << "|" << string (14,' ') << "*   *   * **** *     ***** ****** ********* ****" << string (15,' ') << "|" << endl;
	cout << "|" << string (14,' ') << "*   *   * *    *     *     *    * *   *   * *   " << string (15,' ') << "|" << endl;
	cout << "|" << string (14,' ') << "*   *   * **** *     *     *    * *   *   * ****" << string (15,' ') << "|" << endl;
	cout << "|" << string (14,' ') << "*   *   * *    *     *     *    * *   *   * *   " << string (15,' ') << "|" << endl;
	cout << "|" << string (14,' ') << "********* **** ***** ***** ****** *   *   * ****" << string (15,' ') << "|" << endl;
	cout << "|" << string (77,' ') << "|" << endl << "                  )         (         )                        " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl << "               ) (_)   (   (_)   )   (_) (                     " << string (15,' ') << "|" << endl;   
    cout << "|" << string (77,' ') << "|" << endl << "              (_) # ) (_) ) # ( (_) ( # (_)                    " << string (15,' ') << "|" << endl;        
    cout << "|" << string (77,' ') << "|" << endl << "              _#.-#(_)-#-(_)#(_)-#-(_)#-.#_                    " << string (15,' ') << "|" << endl;    
    cout << "|" << string (77,' ') << "|" << endl << "            .' #  # #  #  # # #  #  # #  # `.                  " << string (15,' ') << "|" << endl;          
    cout << "|" << string (77,' ') << "|" << endl << "           :   #    #  #  #   #  #  #    #   :                 " << string (15,' ') << "|" << endl;   
    cout << "|" << string (77,' ') << "|" << endl << "           | `-.__                     __.-' |                 " << string (15,' ') << "|" << endl;  
    cout << "|" << string (77,' ') << "|" << endl << "           |      `````-----------`````      |                 " << string (15,' ') << "|" << endl;          
    cout << "|" << string (77,' ') << "|" << endl << "           |          NG'S AND AMIR          |                 " << string (15,' ') << "|" << endl;    
    cout << "|" << string (77,' ') << "|" << endl << "           |           BAKERY SHOP           |                 " << string (15,' ') << "|" << endl;        
    cout << "|" << string (77,' ') << "|" << endl << "           |          WE SPECIALIZE          |                 " << string (15,' ') << "|" << endl;          
    cout << "|" << string (77,' ') << "|" << endl << "        _.-|           IN BAKING             |-._              " << string (15,' ') << "|" << endl;  
    cout << "|" << string (77,' ') << "|" << endl << "      .'   '.            CAKES!             .'   `.            " << string (15,' ') << "|" << endl;   
    cout << "|" << string (77,' ') << "|" << endl << "      :      `-.__                     __.-'      :            " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl << "       `.         `````-----------`````         .'             " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl << "         `-.._                             _..-'               " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl << "             `````````-----------`````````                     " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl;              
	
	cout << "|" << string (77,' ') << "|" << endl;
	cout << "|" << string (77,' ') << "|" << endl;
	cout << string(79,'=') << endl;
}

void cakeType ()
{
	int id;
	cout << "Cake ID	Flavor" << endl;
	cout << "0101:		Chocolate" << endl;
	cout << "0102:		White chocolate" << endl;
	cout << "0103:		Vallina" << endl;
	cout << "0104:		Peanut butter" << endl;
	cout << "0105:		Coconut" << endl;
	cout << "0106:		Italian creme" << endl;
	cout << "0107:		Raspberry" << endl;
	cout << "0108:		Banana" << endl;
	cout << "0109:		Lemon" << endl;
	cout << "0110:		Apple" << endl;
	cout << "Enter the cake id :";
	cin >> id;
	
}

void menuExit ()
{
     exit (1);
}

void summary ()
{
	int ii;
	string name2;
	double volume2, price2;
	ifstream myfile;
	myfile.open ("test1.txt");
	while(myfile >> ii >> name2 >> volume2 >> price2)
	{
		cout << ii++ << "." << name2 << "-----" << volume2 << "-----" << price2 << endl;
	}
	myfile.close();
}

int main ()
{
	int i = 1;
	char option;
	string name;
	const float pi = 3.141593;
	const float inch = 0.25;
	double price, height, diameter, radius, volume;

	welcome ();
	
	do{
	cout << string(34,' ') << "Nu1.Bakery" <<string(35,' ') << endl;
	cout << "1.New Order" << endl;
	cout << "2.Cakes Types" << endl;
	cout << "3.Order Summary" << endl;
	cout << "4.Exit" << endl;
	cout << "Please choose the option :";
	cin >> option;
		
	switch (option)
		{
			case '1':
			{
			cout << "Enter your name:";
			getline(cin,name);
			cout << "Enter the diameter:";
			cin >> diameter;
			cout << "Enter the height:";
			cin >> height;
					radius = diameter / 2;
					volume = radius * height * pi * 2;
					price = volume * inch;
			cout << "Price is:" << price << endl;
					ofstream myfile;
					myfile.open("test1.txt", ofstream::out | ofstream::app);
					myfile << i++ << " ";
					myfile << name << " ";
					myfile << volume << " ";
					myfile << price << endl;
					myfile.close ();
			}
			break;
			
			case '2':
			{
			cakeType ();
			}
			break;
			
			case '3':
			{
			summary ();
			}
			break;
			
			case '4':
			{
			menuExit ();
			}
			break;
			default :
				cout << "invalid\n";
		}
		
}while (option > 1 || option <4);
	return 0;
}
The part where you have:
1
2
3
4
5
6
7
8
case '1':
			{
			cout << "Enter your name:";
			getline(cin,name);
			cout << "Enter the diameter:";
			cin >> diameter;
			cout << "Enter the height:";
			cin >> height;


change it to:

1
2
3
4
5
6
7
8
case '1':
			{
			cout << "Enter your name:";
			cin >> name;
			cout << "Enter the diameter:";
			cin >> diameter;
			cout << "Enter the height:";
			cin >> height;


Then it works.

//drmotah
Last edited on
but if i put space between my name... the words after space will not be saved... how???
I'm not sure how to make this exactly but I think an array would help you with this, not entirely sure, sorry. That's beyond what I can do. I think instead of making name a string, make it an array and then spaces will be accepted. I might be entirely wrong so wait for someone else to reply.

//drmotah
basically, thank you...
but i dont really know how to make an array in this... i need some examples.... TT
closed account (28poGNh0)
This statement causing this problem cin >> option;

You're lefting an end line in the buffer ,gets strips by your getline(cin,name);
that's why you cannot enter the name

precede cout << "Enter your name:"; with a cin.ignore()

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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <iostream>
#include <windows.h>
#include <cstdlib>
#include <string>
#include <fstream>

using namespace std;

void welcome ()
{
	cout << string(79,'=') << endl;
	cout << "|" << string (77,' ') << "|" << endl;
	cout << "|" << string (77,' ') << "|" << endl;
	cout << "|" << string (14,' ') << "*   *   * **** *     ***** ****** ********* ****" << string (15,' ') << "|" << endl;
	cout << "|" << string (14,' ') << "*   *   * *    *     *     *    * *   *   * *   " << string (15,' ') << "|" << endl;
	cout << "|" << string (14,' ') << "*   *   * **** *     *     *    * *   *   * ****" << string (15,' ') << "|" << endl;
	cout << "|" << string (14,' ') << "*   *   * *    *     *     *    * *   *   * *   " << string (15,' ') << "|" << endl;
	cout << "|" << string (14,' ') << "********* **** ***** ***** ****** *   *   * ****" << string (15,' ') << "|" << endl;
	cout << "|" << string (77,' ') << "|" << endl << "                  )         (         )                        " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl << "               ) (_)   (   (_)   )   (_) (                     " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl << "              (_) # ) (_) ) # ( (_) ( # (_)                    " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl << "              _#.-#(_)-#-(_)#(_)-#-(_)#-.#_                    " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl << "            .' #  # #  #  # # #  #  # #  # `.                  " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl << "           :   #    #  #  #   #  #  #    #   :                 " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl << "           | `-.__                     __.-' |                 " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl << "           |      `````-----------`````      |                 " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl << "           |          NG'S AND AMIR          |                 " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl << "           |           BAKERY SHOP           |                 " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl << "           |          WE SPECIALIZE          |                 " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl << "        _.-|           IN BAKING             |-._              " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl << "      .'   '.            CAKES!             .'   `.            " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl << "      :      `-.__                     __.-'      :            " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl << "       `.         `````-----------`````         .'             " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl << "         `-.._                             _..-'               " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl << "             `````````-----------`````````                     " << string (15,' ') << "|" << endl;
    cout << "|" << string (77,' ') << "|" << endl;

	cout << "|" << string (77,' ') << "|" << endl;
	cout << "|" << string (77,' ') << "|" << endl;
	cout << string(79,'=') << endl;
}

void cakeType ()
{
	int id;
	cout << "Cake ID	Flavor" << endl;
	cout << "0101:		Chocolate" << endl;
	cout << "0102:		White chocolate" << endl;
	cout << "0103:		Vallina" << endl;
	cout << "0104:		Peanut butter" << endl;
	cout << "0105:		Coconut" << endl;
	cout << "0106:		Italian creme" << endl;
	cout << "0107:		Raspberry" << endl;
	cout << "0108:		Banana" << endl;
	cout << "0109:		Lemon" << endl;
	cout << "0110:		Apple" << endl;
	cout << "Enter the cake id :";
	cin >> id;

}

void menuExit ()
{
     exit (1);
}

void summary ()
{
	int ii;
	string name2;
	double volume2, price2;
	ifstream myfile;
	myfile.open ("test1.txt");
	while(myfile >> ii >> name2 >> volume2 >> price2)
	{
		cout << ii++ << "." << name2 << "-----" << volume2 << "-----" << price2 << endl;
	}
	myfile.close();
}

int main ()
{
	int i = 1;
	char option;
	string name;
	const float pi = 3.141593;
	const float inch = 0.25;
	double price, height, diameter, radius, volume;

	welcome ();

	do
	{
        cout << string(34,' ') << "Nu1.Bakery" <<string(35,' ') << endl;
        cout << "1.New Order" << endl;
        cout << "2.Cakes Types" << endl;
        cout << "3.Order Summary" << endl;
        cout << "4.Exit" << endl;
        cout << "Please choose the option :";
        cin >> option;

        switch (option)
        {
            case '1':
            {
                cin.ignore();
                cout << "Enter your name:";
                getline(cin,name);
                cout << "Enter the diameter:";
                cin >> diameter;
                cout << "Enter the height:";
                cin >> height;
                radius = diameter / 2;
                volume = radius * height * pi * 2;
                price = volume * inch;
                cout << "Price is:" << price << endl;
                ofstream myfile;
                myfile.open("test1.txt", ofstream::out | ofstream::app);
                myfile << i++ << " ";
                myfile << name << " ";
                myfile << volume << " ";
                myfile << price << endl;
                myfile.close ();
            }
            break;
            case '2':
                cakeType ();
            break;
            case '3':
                summary ();
            break;

            case '4':
                menuExit ();
            break;
            default :
                cout << "invalid\n";
        }

    }while (option > 1 || option <4);
	return 0;
}



surprisingly, it works!!!! oic... now only i realize tat...by the way... thank a lot...
You have (at least) two problems.
1) You have a newline character left over in your input buffer.
At line 84, you define option as a char.
At line 99, you do a cin. That will read one char from cin. The newline will be left in the buffer. At line 106, you do a getline to name, but the \n is still in the buffer, therefore the getline completes immediately with an empty name.

2) You're inconsistent in your use of option. At line 146, you're comparing option (a char) against the numbers 1 and 4. You should be comparing against character literals.
Topic archived. No new replies allowed.