Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include <stdio.h>

//function declaration
void dispTariff(float);
float getTariff(int);

//declare and initialize data
int eusage[]={800,650,525,450,420,405,400,400,400,400};
#define tariff 25;
void main(void)
{
	float usageA,usageB,increase;
	usageA=getTariff(5);
	usageB=getTariff(8);
	increase=((usageB-usageA)/usageA*100);

	//print increase in percentage
	printf("increase in percentage is %2.2f%%\n",increase);

}//main
float getTariff(int duration)
{
	int j=0;
	float ebill=0;
	for(j=0,j<duration;j++;)>
	{
		ebill=ebill+tariff*(eusage[j]/1000.0);
	}
	printf("total bill after 6 hours %.2fcent\n",ebill);
	return ebill;
}
Posted
Updated 12-Jan-16 22:49pm
v3

1 solution

The error source is here:
#define tariff 25;

The preprocessor will replace the occurence of tariff with 25; so that the compiler later sees this line:
ebill=ebill+25;*(eusage[j]/1000.0);

The semicolon defines the end of an expression and *(eusage[j]/1000.0) is interpreted as another expression where the indirection operator (*) is applied to a non-pointer value.
So change it to:
#define tariff 25


But there is also another error in your code. The line
for(j=0,j<duration;j++;)

should probably be
for(j=0;j<duration;j++)
 
Share this answer
 
Comments
_Asif_ 13-Jan-16 6:42am    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900