declare variables

Jun 25, 2013 at 10:37pm
I receive the "not decared in this scope" message for "total" in line 23. I though I declared it in the main method?

//this programs calls a variety of methods to calculate the coins in a jar

#include <iostream> // Controls input and output in a C++ program
using namespace std; // "Palette" upon which program is written


void enterCurrency();
void accumulateCurrency(double &total,double amountCurrency);
void countItems(int &numberCurrencyItems);
void printTotalAverage(double total,int numberCurrencyItems);


int main ()
{




enterCurrency();
accumulateCurrency(total,amountCurrency);
countItems(numberCurrencyItems);
printTotalAverage(total,numberCurrencyItems);


}
amountCurrency= void enterCurrency()
{
//declarations for varialbes

double amountCurrency;
int numberCurrencyItems=0;
double total=0;

//enter the amount of a coin
cout<<"Enter currency Amount, or 0 the end \n";
cin>> amountCurrency;

//execute while there currency in the jar
while (amountCurrency!=0)
{
//accumulate a total of bills/coins method
void accumulateCurrency(double &total, double amountCurrency)
{
//accumulate a total of bills/coins
total=total+amountCurrency;
}

//count the number of coins/bills method
void countItems(int &numberCurrencyItems)
{
//count the number of coins/bills
numberCurrencyItems=numberCurrencyItems+1
}

//enter the amount of a coin
cout<<"Enter currency Amount, or 0 the end \n";
cin>> amountCurrency;

}
}

//print total average method
void printTotalAverage(double total,int numberCurrencyItems)
{


//print out data and calculate average
cout<<"\n\n";
cout<<" The total of the currency is : "<<total<<"\n\n";
cout<<" The average of each Coin/Bill is : "<<total/numberCurrencyItems<<"\n\n";

}




Jun 25, 2013 at 10:43pm
Any name shall be declared before its usage. You are calling function accumulateCurrency with argument total

accumulateCurrency(total,amountCurrency);

but total was not declared before this call.
Jun 25, 2013 at 10:48pm
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.
Topic archived. No new replies allowed.