Void Functions: passed by value help.. to find a total

I missed last class on doing void functions because I got sick and im completely lost! ive being using the texts book example for a reference but its not running ! Can someone please help me alter my code so it will work

the output should look similar to this:
how much was your shirt?
20
shirt 20.00
tax =1.20
the total 21.20


include <iostream>
#include <iomanip>
using namespace std;

void getShirtCost(double shirtCost);
void calculate(double shirtCost,double taxAmount, double total, double taxamount) ;
void printReceipt(double shirtCost, double taxAmount, double total, double taxamount);
int main ()
{
//declaration secetion

double shirtCost, taxAmount,total,taxamount;
cout<< fixed<<showpoint;
cout.precision(2); //sets the 'double/float' data types 2 decimal places

cout<<"Enter the proce of the t-shirt<"<< endl;

getShirtCost(shirtCost);
calculate(shirtCost,taxAmount,total,taxamount);
printReceipt(shirtCost,taxAmount,total,taxamount);

system ("PAUSE");
return 0;
}
void getShirtCost(double shirtCost)
{
cin >> shirtCost;
}

void calculate(double shirtCost,double taxAmount, double total, double taxamount )
{
taxAmount= 6;
taxamount= shirtCost*taxAmount*.01;
total= shirtCost+taxamount;
}

void printReceipt(double shirtCost, double taxAmount, double total, double taxamount)
{
cout << "This is your shirt cost" <<shirtCost<< endl;
cout << "This is your tax amount" <<taxamount<< endl;
cout << "Your overall total is" << total<< endl;
}

use code tags please.

getShirtCost(shirtCost);

pass by reference: http://www.learncpp.com/cpp-tutorial/73-passing-arguments-by-reference/ . otherwise when you cin the input it'll be lost when the function completes.

Your compiler should have told you with something like this:
error C4700: uninitialized local variable 'shirtCost' used
Last edited on
Topic archived. No new replies allowed.