"Pretty bird...Pretty bird"

Any suggestions for this program?
It works. Just looking for pointers. Thanks!
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
  #include <iostream>
#include <iomanip>
using namespace std;


//*****function prototypes*********
double getStandard(double sub);
double getPremium(double sub);

int main()
{
	double subtotal = 0.0;
	char member = ' ';
	double total = 0.0;

	cout << "Please enter the subtotal: ";
	cin >> subtotal;
	
	while (subtotal < 0)
	{
		cout << "Enter a valid subtotal: " << endl;
		cin >> subtotal;
	}
	
	cout << "Are you a Premium Member (Y/N)? ";
	cin >> member;

	while (toupper(member) != 'Y' && toupper(member) != 'N')
	{
		cout << "Are you a Premium Member? Y(yes) or N(no)" << endl;
		cin >> member;
	}
	
	if  (toupper(member) == 'N')
			total = getStandard(subtotal);  //***pass the getStandard function the subtotal input***
	
	else 
		total = getPremium(subtotal);  //***pass the getPremium function the subtotal input***
	//***end if***

	cout << fixed << setprecision(2);
	cout << "The total due including shipping: " << total << endl;


	system("pause");
	return 0;
}
//*********function definitions****************
double getStandard(double sub)
{
	double standard = 0.0;
	if (sub >= 0 && sub <= 100)
		standard = sub + 12.99;
	
	else 
		standard = sub + 4.99;
	//end if
	return standard;
}//end getStandard function

double getPremium(double sub)
{
	double premium = 0.0;
	if (sub >= 0 && sub <= 49.99)
		premium = sub + 4.99;
	
	else
		premium = sub;
	//end if
	return premium;
pointers, you say?

ok

1
2
3
0x00000005
0xF00034FA
0x00000812
^^
Ha ha guess i set myself up there
well, you could set up input checking, for when the user enters an invalid value.

1
2
if (!cin)
  std::cout << "Err";
In place of this?

1
2
3
4
while (subtotal < 0)
	{
		cout << "Enter a valid subtotal: " << endl;
		cin >> subtotal;
No, in front of each cin. By the way, you could force the user to enter a valid integer each time.
1
2
3
4
while (subtotal < 0 || (!cin))
	{
		cout << "Enter a valid subtotal: " << endl;
		cin >> subtotal;


this could work
Last edited on
ok Im still n00bish haven't gotten
(!cin)
status yet. I'll give it a shot though. Thanks!

Agario is awesome i love that game
YAY, SOMEONE LIKES AGARIO TOO.

!cin is a validator, that validates cin, if cin fails, it returns false,. It fails when invalid input is given, such as input being too long, or being non char. This is good because most compilers go into this random infinite loop after failing cin.

Ps: Me and my friend's channel is TNT clan, search it up, you might find me, runner
Topic archived. No new replies allowed.