Cash Register?

I'm not sure if my functions are written properly, or if I'm incorporating them into my main code the right way. I'm getting a lot of weird output errors that I don't really understand. I need to change my functions up, as well as add some "; before }", so i assume those will be return;? Please help lol I'm so confused:




This program totals any number of items purchased by any number of customers. When you're done, it gives you the number of customers and the total of all the sales.

I'll give you the function prototype for the function I want you to use to input the items and calculate the total sale for one customer.

double Sale(int Count);

Below is a typical output.

This program computes the items sold to multiple customers.
A negative sale amount will complete the entry for that customer.

Do you have a new customer (Y / N)? y

Input an item cost: 2.56
Input an item cost: 1.24
Input an item cost: 3.99
Input an item cost: -1

The total for customer No. 1 is $ 7.79

Do you have a new customer (Y / N)? y

Input an item cost: 6.55
Input an item cost: 4.44
Input an item cost: -1

The total for customer No. 2 is $ 10.99

Do you have a new customer (Y / N)? n


The total of the 2 sales is $ : 18.78

Press any key to continue . . .


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;

void title(void);
double sale(int Count);
char input(void);

char mychar;
double totsale = 0.0, total = 0.0, cost = 0.0;
int n = 0, count = 0;

int main()
{
	

	title(); //print our preprogrammed message	

	cout << "Do you have a new customer (Y / N)? ";
	cin >> mychar;
	if(mychar > 90)
		mychar -= 32;
	if(mychar == 'Y')
	{
		count = count + 1;
		n = n + 1;
	cout << "\nInput an item cost: ";
	cin >> cost;

		while(cost > 0)
		{
			cout << "\nInput an item cost: ";
			cin >> cost;
			total += cost;
		}
		
		totsale += total;
	
		void Output(int n, double total)
;
	}

if(mychar == 'N')
	
		double Sale(int count)
}
Title(void)
{
  cout << "\nThis program computes the items sold to multiple customers.";
  cout << "\nA negative sale amount will complete the entry for that customer.\n";
}

void Output (int n, double total)
{
  cout << "The total for customer No. " << n << " is $" <<total<<;
  cout << "\n ";
}

double Sale(int count)
{
	cout << "\nThe total of the " >> count >> " sales is $" >> totsale;
}

}
Everywhere you make a function call: You need to get rid of those types at the beginning and in the parentheses. Else, C++ will treat them as declarations, which you don't want.

Lines 20 and 21: Not a compilation error, but there are simpler and more legible ways to do what I think you want to do. See: http://www.cplusplus.com/reference/cctype/

Line 24: Prime example of why you shouldn't use using namespace. Namespace std has something called count, and when you have a global variable (something that you also shouldn't use) called count as well, the compiler doesn't know which you mean. Either get rid of the global variables, or get rid of using namespace, but preferably both. :P

Line 38: You forgot to declare Output before you call it in main().

Line 44: Missing semicolon, capitalization issues.

Line 46: Missing return type, capitalization issues.

Line 54: You have one << too many on the end.

Line 58: Capitalization issues, you never ultimately return a double so why do you have that specified as the return type?

Line 60: You're mixing <<s and >> s. Are you sure you meant to do that?

Line 63: One closing-bracket too many (I think).

You may want to read these:
http://www.cplusplus.com/doc/tutorial/functions/
http://www.cplusplus.com/doc/tutorial/functions2/

-Albatross
Last edited on
I worked out some more of it, my only problem is now with this:

void Output(int,double)' : overloaded function differs only by return type from 'int Output(int,double)

Here is my fixed code. I'm confused on return types, I've pretty much assumed it is always return 0; up until this assignment. My program is running and the while look is working, however as soon as I type in a negative number the program goes to "press any key to continue" when it should prompt for a new customer. I changed my second if to a while, but that still hasnt fixed 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
64
65
66
67
#include<iostream>
using namespace std;

void title(void);
double sale(int counts);
char input(void);
int Output (int n, double total);

char mychar;
double totsale = 0.0, total = 0.0, cost = 0.0;
int n = 0, counts = 0;

int main()
{
	

	title(); //print our preprogrammed message	

	cout << "Do you have a new customer (Y / N)? ";
	cin >> mychar;
	if(mychar > 90)
		mychar -= 32;
	while(mychar == 'Y')
	{
		counts = counts + 1;
		n = n + 1;
	cout << "\nInput an item cost: ";
	cin >> cost;

		while(cost > 0)
		{
			cout << "\nInput an item cost: ";
			cin >> cost;
			total += cost;
		}
		
		totsale += total;
	
		int Output(int n, double total);
return 0;
	}

if(mychar == 'N')
	
		double sale(int counts);
return 0;

}
void title(void)
{
  cout << "\nThis program computes the items sold to multiple customers.";
  cout << "\nA negative sale amount will complete the entry for that customer.\n";
}

int output (int n, double total)
{
  cout << "The total for customer No. " << n << " is $" << total;
  cout << "\n ";
return 0;
}

double sale(int counts)
{
	cout << "\nThe total of the " << counts << " sales is $" << totsale;
return 0;

}
Last edited on
Topic archived. No new replies allowed.