hello, i have write a program and when i compile it, it say that one of my variable 'advance', is a ambiguous symbol and cannot be used....why? after i change the 'advance' to other word, like 'advanced', it run nicely....but why 'advance' word is ambiguous in this program?

#include <iostream>
using namespace std;
double commission (double sales);
double pay, sales, advance ,com,rate;


int main ()
{
	cout<<"What is your monthly sales? "<<endl;
	cin>>sales;
	cout<<"How much advanced pay you have drawn? "<<endl;
	cin>>advance;
	commission (sales);
	cout<<"your commission is RM "<<sales*rate/100<<endl;
	cout<<"After subtractring the advanced pay.... "<<endl;
	pay=(sales*rate/100)- advance;
	cout<<"\n*****************************************************"<<endl;
	cout<<"Your total commission pay is   RM "<<pay<<endl;
	cout<<"*****************************************************\n"<<endl;
	
	if (pay<0)
		cout<<"You must reimburse the company a total of RM "<<-1*pay<<" !!\n"<<endl;
	return 0;
}

double commission (double sales)
{
	
	
		if (sales<10000) rate=5; 
		if (sales>=10000&&rate<15000) rate=10; 
		if (sales>=15000&&rate<18000) rate=12; 
		if (sales>=18000&&rate<22000) rate=14; 
		if (sales>=22000) rate=16; 
	cout<<"\nCommission rate = "<<rate<<"%"<<endl;
	
	return rate;
}

> my variable 'advance', is a ambiguous symbol and cannot be used....why?
the c++ standard library defines a function std::advance (header <iterator> ; the function is used to move an iterator by a certain distance). your program would be (indirectly) including this header and also has a using namespace std ; directive. if you also define a variable at global scope with the name advance, the unqualified reference to identifier 'advance' becomes ambiguous.

> after i change the 'advance' to other word, like 'advanced', it run nicely....
after you change the name, the name clash is no longer there.
you can also get rid of the ambiguity by moving the definition of the variable advance from global scope to inside (the local scope of) main.
another way is to always specify the fully qualified name for advance; std::advance for the standard library function and ::advance for your (global) variable.
yet another solution would be to remove the using directive using namespace std ; and instead have using declarations eg.

using std::cin ;
using std::cout ;
using std::endl ;
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.