In Need of Assistance Please

Hi i have to write a code that allows the user to key in any number of item prices for items purchased in a discount store. Display the grand total amount of all items including an addition of 8% tax on all items. this is what i have so far, I can get it to compile and run but it doesn't seem to be right.

#include <cstdlib>
#include <iostream>

using namespace std;

void menu(); // functions
void calculate(); // functions
void display(); // functions

int choice;
int i=0;
double total;


int main()
{

menu();

return 0;
}

void menu(){
do
{

cout<<"1- To Enter Item Prices "<<endl;
cout<<"2- To Display Total"<<endl;
cout<<"3- TO QUIT: )"<<endl;
cin>>choice;

switch (choice)
{
case 1:
calculate();
break;
case 2:
display();
break;
case 3:
break;
}
}
while(choice>0 && choice<3);

}



void calculate()
{
int temp=1;
cout<<"Enter item Price (negative to Quit):\n "<<endl;
while(temp>0)
{
i++;
cin>>temp;
if(temp<=0) break;
total+=temp*1.08;
}
menu();
}


void display()
{
cout<<" The total price of all items, including 8% tax is $"<<total<<endl;
menu();
}

What's not right about it? It seems to work for me.
Ctrygirl, i have not looked at your code but might I recommend something for determining if your values are right?

I was always taught in school to test these kinds of functions by hand, that is.. get a calculator, plug in some numbers to fit the equation(i assume its just the total of your items and add the .08% tax)

So try somethign liek this on paper.

item 1 : 50.0
item 2 : 28.3
item 3: 40.9
item total : 50.0 + 28.3 + 40.9
tax : (50.0 + 28.3 + 40.9) * .08
grand total : Total + tax

now plug those same numbers into your program

Does your program return the same value as a grand total? If it does, your code appears to be working properly (;

You can run the pen paper calculator test a few times if you don't feel secure with just one run through.
I changed some stuff you can check it out see if you like dislike w-e. you did have a couple lil issues in there . for one temp needs to be a double an prolly more effectively an array here you'll c

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
double temp[]
void calculate()
{
;
cout<<"Enter item Price (negative to Quit):\n "<<endl;
while(i=0,temp[i]>0)
{

cin>>temp[i];
if(temp<=0)
	break;

else
total+=temp[i]*1.08;
i++;
}
menu();
}


void display()
{
cout<<" The total price of all items, including 8% tax is $"<<total<<endl;

menu();} // would add delay b4 this



//in milliseconds
void delay(double x)     
{
	int y;
	for(y=0;y<x;y++)
	(x *10000)/.01;

}


double checkout(double temp[],int i)
	{int z;

for(z=0;z<i;z++)
{  temp[z+1]= temp[z] + temp[z+1];

}
total=temp[z+1];

cout<<"Total is"<<total;
delay(5000);
menu();

}
@markyrocks when i tried your code i got an error message on line 2
line 4 there a stray ; I didn't write this to b a functional program. It was more to give you ideas.
Last edited on
I'm still getting an error it says expected init-declarator before "void"
well what are you doin are you tryin to compile the code i wrote by itself or add it to your program an compile?
i am trying to compile the code you wrote by itself
You have to have a main() function.
i added main() but now there is an error on double temp[]
marky only gave you a sample of code to be added in to your program. He didn't give you a complete program all on it's own. It's supposed to lead you in the direction of critical thought and self-education, not do it for you. See if you can find a way to add marky's code into your original program.
double calculate()
{i=0;

cin>>in;
{ while(in>0)
cout<<"Enter item Price (negative to Quit):\n ";

temp1[i]=in;
i++;
return 0;
}

gettin unresolved externals error have no clue why and i can't be messin with this all nite
'i' isn't declared in this scope, and the '{' before while(in>0) isn't necessary.
okay never mind this is just confusing me even more, thank you for trying to help though
Topic archived. No new replies allowed.