How to cin??

My cin for "quantity" is not working Help?

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
 // This Program is for Homework #5, Frederick A. Bowser
// Define named constants; line, item prices, etc.
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <cstdlib>

using namespace std;
int main ()
{
	const string menu =
	" [01] Meat	   [02] Bakery  [03] Fruits     [04] Frozen \n"
	" [05] Milk & Diary [06] Drinks	[07] Cereal	[08] Snacks \n";
	cout << menu << endl;
	cout << "______________________________________________________________________" << endl;
double A,B,C,D;
	
	int choice;
	choice = 1,2,3,4,5,6,7,8;
	cout << "Which would you like = " << endl;
	cin >> choice;
if (choice == 1)
	{ cout <<  " [A] bacon	   [B] hotdog  [C] beef    [D] steak \n";}
if (choice == 2)
	{ cout <<  " [A] bread	   [B] cake    [C] cupcake [D] cookies \n";}
if (choice == 3)
	{ cout <<  " [A] apples   [B] Banana  [C] grapes  [D] strawbarry \n";}
if (choice == 4)
	{ cout <<  " [A] pizza	   [B] wings   [C] TvDinners [D] ice \n";}
if (choice == 5)
	{ cout <<  " [A] milk	   [B] cheese  [C] yogurt    [D] butter \n";}
if (choice == 6)
	{ cout <<  " [A] soda	   [B] water  [C] fruit juice  [D] ice tea \n";}
if (choice == 7)
	{ cout <<  " [A] Corn Flakes [B] Apple Jacks  [C] Coco Puffs  [D] Chex Mixs  \n";}
if (choice == 8)
	{ cout <<  " [A] Honey Buns [B] Chips  [C] Candy  [D] Gum  \n";}
cout << "_________________________________________________________________________" << endl;

cout << " what would you like = ";

	cin >> A,B,C,D;
cin >> quantity;

A= 2.25; 
	B= 1.52;
	C= 3.85;
	D= 1.75;
	
	




	return 0;
}
Last edited on
cin >> A,B,C,D;:

I think this will not work, try this instead:

cin >> A >> B >> C >> D;
( just remember you need to put spaces beetween them when typing )

And you have not declared a quantity variable, so how could you use it ?
Last edited on
In the future, if you have a thread posted to ask for help on a program, then don't make another thread to ask for help on the same program.

Line 43 is useless. You set the new values anyways. Your user is trying to give you a char, so your doubles won't work. In fact, my input stream is corrupted when you use a character for line 43.

With the stream becoming corrupt, line 44 is useless.

I believe this will show you what I mean if you compile it.

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
// This Program is for Homework #5, Frederick A. Bowser
// Define named constants; line, item prices, etc.
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <cstdlib>

using namespace std;
int main ()
{
	const string menu =
	" [01] Meat	   [02] Bakery  [03] Fruits     [04] Frozen \n"
	" [05] Milk & Diary [06] Drinks	[07] Cereal	[08] Snacks \n";
	cout << menu << endl;
	cout << "______________________________________________________________________" << endl;
double A,B,C,D;
int quantity;
	
	int choice;
	choice = 1,2,3,4,5,6,7,8;
	cout << "Which would you like:   ";
	cin >> choice;
if (choice == 1)
	{ cout <<  " [A] bacon	   [B] hotdog  [C] beef    [D] steak \n";}
if (choice == 2)
	{ cout <<  " [A] bread	   [B] cake    [C] cupcake [D] cookies \n";}
if (choice == 3)
	{ cout <<  " [A] apples   [B] Banana  [C] grapes  [D] strawbarry \n";}
if (choice == 4)
	{ cout <<  " [A] pizza	   [B] wings   [C] TvDinners [D] ice \n";}
if (choice == 5)
	{ cout <<  " [A] milk	   [B] cheese  [C] yogurt    [D] butter \n";}
if (choice == 6)
	{ cout <<  " [A] soda	   [B] water  [C] fruit juice  [D] ice tea \n";}
if (choice == 7)
	{ cout <<  " [A] Corn Flakes [B] Apple Jacks  [C] Coco Puffs  [D] Chex Mixs  \n";}
if (choice == 8)
	{ cout <<  " [A] Honey Buns [B] Chips  [C] Candy  [D] Gum  \n";}
cout << "_________________________________________________________________________" << endl;

cout << " what would you like:  ";

	//cin >> A,B,C,D;
	cin >> A >> B >> C >> D;
	cin >> quantity;

	cout << A << " " << B << " " << C << " " << D << " " << quantity << endl;

A= 2.25; 
	B= 1.52;
	C= 3.85;
	D= 1.75;

	cout << A << " " << B << " " << C << " " << D << endl;
	
	




	return 0;
}
Last edited on
Topic archived. No new replies allowed.