Debug

can someone please help me debug this?

// User enters price
// program computes tax rate
// 5% at $10 and under, otherwise 7%
#include<iostream.h>
#include<conio.h>

void main()
{
double askPrice();
double calcTax(double price);
double price;
double taxRate;
askPrice();
calcTax();
cout<<"On $"<<price<<", the taxRate is "<<taxRate<<endl;
getch();
}
double askPrice()
{
double price;
cout<<"Enter price $";
cin>>price;
return price;
}
double calcTax()
{
double rate;
if(price<=10)
rate = .05;
else rate = .07;
return rate;
}
Compare:
double calcTax(double price);
with:
1
2
3
4
double calcTax()
{
...
}
what do you mean by compare?
The double price variable declared inside function askPrice is not the same as the double price variable declared inside main. So askPrice prompts for the price, reads the value into its local price variable and then returns it as the result of the function. Back in main(), the result of the function isn't assigned to anything so it gets thrown away, leaving the price variable inside main uninitialized.

As coder777 points out, you declare a function calcTax(double price) inside main. Then you call it without passing any parameters. This is a compiler error. You need to change the definition of calcTax to be double calcTax(double price)

If all of this is hard to follow it's because I can't refer to line numbers. Please edit your post, highlight the code and click the <> button to the right of the edit window. This will cause the code to show up with syntax highlighting and line numbers. It's a beautiful thing.
Registered users can post here. Sign in or register to post.