cant put next customer name.

this is my source code.
after i input 'Y' at "PROCEED WITH NEW CUSTOMER(Y/ N)" i cant input a new name.
need helppppp. :)

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
#include <iostream>
using namespace std;
int main(){
	float weight,price;
	char i='Y';
	
string  name,address,phonenumber,postalcode,state;

while (i!='N'|| i!='n')
{
	cout<<"\n****************WELCOME TO SUPER POSTAGE SERVICE*******************\n";
	
	cout<<"\nEnter Customer Name: ";
	getline(cin,name);
	cout<<"\nEnter Customer Address: ";
	getline(cin,address);
	cout<<"Postal Code: ";
	getline(cin,postalcode);
	cout<<"Enter State: ";
	getline(cin,state);
	cout<<"Enter Customer Phone Number: ";
	cin>>phonenumber;
	cout<<"Enter Items Weight(In Kg) :";
	cin>>weight;
	
	if (weight<0.5){
		price=5.9;
	}
	else if (weight>=0.5 && weight<1.0){
		price=5.9+1;
	}
	else if (weight>=1.0 && weight<1.5){
		price=5.9+1+1;
	}
	else if (weight>=1.5 && weight<2){
		price=5.9+1+1+1;
	}
	else if (weight>=2 && weight<5){
	    price=15;
	}
	else if (weight>=5 && weight<10){
		price=15+5;
	}
	else if(weight>=10 && weight<15){
		price=15+5+5;
	}
	else if (weight>=15 && weight<20){
		price=15+5+5+5;
	}
	else if (weight>=20 && weight<25){
		price=15+5+5+5+5;
	}
	else if (weight>=25 && weight<=30){
		price=15+5+5+5+5+5;
	}
	else 
	{
		price=0;
	}
	cout<<"\n************************************************";
	cout<<"\nThe Customer Name: "<<name;
	cout<<"\nThe Customer Address: "<<address;
	cout<<"\nPostal Code:"<<postalcode;
	cout<<"\nState: "<<state;
	cout<<"\nThe Customer Phone Number: "<<phonenumber;
	if(weight>0 && weight<=30)
	{
	cout<<"\nPRICE: RM"<<price;
	}
	else
	{
		cout<<"\nPrice: invalid (Our Weight Limit is 30Kg)";
	}
	cout<<"\n************************************************\n";

cout<<"\n*************************************";
cout<<"\n\nPROCEED WITH NEW CUSTOMER(Y/ N) : ";
cin>>i;
cout<<"\n*************************************";

}

}  Put the code you need help with here.
Hello bigboss98,

In the while condition, line 9, When using "1=" "&&" works best not "||".

Give it a try,

Hope that helps,

Andy

this is my output, you can see the second "Enter customer name " part is blank. i still cant find the problem.



****************WELCOME TO SUPER POSTAGE SERVICE*******************

Enter Customer Name: a

Enter Customer Address: 3
Postal Code: 3
Enter State: 3
Enter Customer Phone Number: 3
Enter Items Weight(In Kg) :3

************************************************
The Customer Name: a
The Customer Address: 3
Postal Code:3
State: 3
The Customer Phone Number: 3
PRICE: RM15
************************************************

*************************************

PROCEED WITH NEW CUSTOMER(Y/ N) : y

*************************************
****************WELCOME TO SUPER POSTAGE SERVICE*******************

Enter Customer Name:
Enter Customer Address: a
Postal Code: a
Enter State: a
Enter Customer Phone Number: 3
Enter Items Weight(In Kg) :3

************************************************
The Customer Name:
The Customer Address: a
Postal Code:a
State: a
The Customer Phone Number: 3
PRICE: RM15
************************************************

*************************************

PROCEED WITH NEW CUSTOMER(Y/ N) : y

*************************************
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
#include <iostream>
using namespace std;

int main()
{
    double weight,price;
    char yes_no = 'Y';
    string name, address, phonenumber, postalcode, state;

    while( yes_no != 'N' && yes_no != 'n' ) // *** &&
    {
        cout << "\n****************WELCOME TO SUPER POSTAGE SERVICE*******************\n";

        cout << "\nEnter Customer Name: ";
        getline(cin,name);
        cout << "\nEnter Customer Address: ";
        getline(cin,address);
        cout << "Postal Code: ";
        getline(cin,postalcode);
        cout << "Enter State: ";
        getline(cin,state);
        cout << "Enter Customer Phone Number: ";
        cin>>phonenumber;
        cout << "Enter Items Weight(In Kg) :";
        cin>>weight;

        if( weight<0.5 ) price = 5.9;
        else if( weight<1.0 ) price = 5.9+1;
        else if( weight<1.5) price = 5.9+1+1;
        else if( weight<2 ) price = 5.9+1+1+1;
        else if( weight<5 ) price = 15;
        else if( weight<10 ) price = 15+5;
        else if( weight<15 ) price = 15+5+5;
        else if( weight<20 ) price = 15+5+5+5;
        else if( weight<25 ) price = 15+5+5+5+5;
        else if( weight<=30 ) price = 15+5+5+5+5+5;
        else price = 0;

        cout << "\n************************************************";
        cout << "\nThe Customer Name: " << name;
        cout << "\nThe Customer Address: " << address;
        cout << "\nPostal Code:" << postalcode;
        cout << "\nState: " << state;
        cout << "\nThe Customer Phone Number: " << phonenumber;

        if( weight>0 && weight<=30 ) cout << "\nPRICE: RM " << price  <<  '\n' ;
        else cout << "\nPrice: invalid (Our Weight Limit is 30Kg)\n";

        cout << "\n************************************************\n";

        cout  <<  "\n*************************************";
        cout  <<  "\n\nPROCEED WITH NEW CUSTOMER(Y/ N) : ";
        cin  >> yes_no ;
        cout  <<  "\n*************************************";

        // *************** added ************************
        // there would be a new line remaining in the input buffer after cin >> yes_no
        // extract it and throw it away (or else the next getline will see it as end of line)
        // https://en.cppreference.com/w/cpp/io/basic_istream/ignore
        std::cin.ignore( 1000, '\n' ) ;
        // ***************************************************
    }
}
MR JLBORGES.
STILL CANT INPUT A NEW NAME, IT STIL JUST BLANK...
HOWWWWWWWWWWW;

I COPIED YOUR ALSO CANNOT INPUT A NEW NAME.
Last edited on
Hello bigboss98,

This works for my computer.
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
#include <iostream>
#include <string>
#include <limits>

//using namespace std;  // <--- Best tno to use.

int main()
{
	double weight{}, price{};
	char i = 'Y';

	std::string  name, address, phonenumber, postalcode, state, city;  // <--- Added City.

	while (i != 'N' && i != 'n')
	{
		std::cout << "\n****************WELCOME TO SUPER POSTAGE SERVICE*******************\n";

		std::cout << "\nEnter Customer Name: ";
		std::getline(std::cin, name);
		std::cout << "\nEnter Customer Address: ";
		std::getline(std::cin, address);
		std::cout << "Enter City: ";   // <--- Added.
		std::getline(std::cin, city);  // <--- Added.
		std::cout << "Enter State: ";
		std::getline(std::cin, state);
		std::cout << "Postal Code: ";
		std::getline(std::cin, postalcode);
		std::cout << "Enter Customer Phone Number: ";
		std::getline(std::cin, phonenumber);
		std::cout << "Enter Items Weight(In Kg) :";
		std::cin >> weight;
		std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>.  // <--- Added.

		if (weight < 0.5)
			price = 5.9;
		else if (weight >= 0.5 && weight < 1.0)
			price = 5.9 + 1;
		else if (weight >= 1.0 && weight < 1.5)
			price = 5.9 + 1 + 1;
		else if (weight >= 1.5 && weight < 2)
			price = 5.9 + 1 + 1 + 1;
		else if (weight >= 2 && weight < 5)
			price = 15;
		else if (weight >= 5 && weight < 10)
			price = 15 + 5;
		else if (weight >= 10 && weight < 15)
			price = 15 + 5 + 5;
		else if (weight >= 15 && weight < 20)
			price = 15 + 5 + 5 + 5;
		else if (weight >= 20 && weight < 25)
			price = 15 + 5 + 5 + 5 + 5;
		else if (weight >= 25 && weight <= 30)
			price = 15 + 5 + 5 + 5 + 5 + 5;
		else
			price = 0;

		// <--- Rearranged the output.
		std::cout << "\n************************************************";
		std::cout << "\nThe Customer Name: " << name;
		std::cout << "\nThe Customer Address: " << address;
		std::cout << "\nCity: " << city << "\tState: " << state << "\tPostal Code : " << postalcode;
		std::cout << "\nThe Customer Phone Number: " << phonenumber;

		if (weight > 0 && weight <= 30)
		{
			std::cout << "\nPRICE: RM " << price;
		}
		else
		{
			std::cout << "\nPrice: invalid (Our Weight Limit is 30Kg)";
		}
		std::cout << "\n************************************************\n";

		std::cout << "\n*************************************";
		std::cout << "\n\nPROCEED WITH NEW CUSTOMER(Y/ N) : ";  // <--- Do not shout!
		std::cin >> i;
		std::cout << "\n*************************************";

		std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>.  // <--- Added.

	}

	return 0;
}


Hope that helps,

Andy
Topic archived. No new replies allowed.