I'm writing a program that uses functions that I create.It hasn't been much trouble until I got to a point where I am supposed to create a function that calculates the total of everything bought with sales tax. the problem is I can't get the total which has already been calculated to go to the next function. If you are kind of lost on what I'm saying just look at the code.

``````#include <iostream.h>

void get_total (float &total);
void calculate_total (float total);

int main ()
{
float total;

get_total (total);
calculate_total (total);

return 0;
}

void get_total (float &total)
{
char choice;
const int T = 0;
const int X = 0;

do
{
cout << "S = sandwhich\n";
cout << "C = chips\n";
cout << "B = brownie\n";
cout << "R = regular drink\n";
cout << "L = large drink\n";
cout << "X = cancel sale\n";
cout << "T = total sale\n";
cin >> choice;

if (choice == 'T')
{break;}

switch (choice)
{
case 'S':
total = total + 3.50;
break;
case 'C':
total = total + .75;
break;
case 'B':
total = total + .75;
break;
case 'R' :
total = total + .50;
break;
case 'L':
total = total + 1.00;
break;
case 'X':
total = 0;
break;
default:
cout << "illegal entry\n";
break;
}
cout << "the total sale without tax is \$" << total << endl;
}
while (choice != 'T');
}

void calculate_total (total)
{
cout << total;
}
``````

I am required to use a separate function to calculate the total with tax, right now i'm just trying to get the total to output in it and after I can do that I'll find the total with tax. I've been getting two error messages along with a bunch of warnings they are:

``````warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
there are 5 of them but I'm not to worried about them.
and:
error C2065: 'total' : undeclared identifier
error C2448: '<Unknown>' : function-style initializer appears to be a function definition
``````

thanx to anyone who helps :)

## All 4 Replies

See what's missing in the function definition?

``````void calculate_total ([b]float [/b]total);
/*...*/
void calculate_total (total)
{
cout << total;
}``````

At some point you'll probably want to initialize your total.

``float total = 0;``

A float constant would be 3.50F, whereas a double constant would be 3.50.

``````void calculate_total (total)
{
cout << total;
}``````

has to be

``````void calculate_total (float &total)
{
cout << total;
}``````

your compiler interprets literals like 0.75 as double.
K.

``````void calculate_total (total)
{
cout << total;
}``````

has to be

``````void calculate_total (float &total)
{
cout << total;
}``````

Bzzzzzzzt!

Bzzzzzzzt!

guess there is an "&" too many :sad:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.