first C++ program - computing taxes

hey everybody, this is my first program, and taking the first programming class in school, and our teacher wants us to write a simple program that will calculate the total cost of something, including sale price and tax added. but i am stuck, so any help offered would be great. the code i have written (but doesn't work is as follows:

#include <iostream>
using namespace std;

int main ()
{
double rate, price, tax, cost;
rate = 0.08;
cost = tax + price;
cout << "Enter the original price.";
cin >> price;
cout << "Determine amount of tax.";
cin >> "rate * price";
cout << "The total cost is $" << cost << endl;
return 0;
}

if someone could point out my errors, i would appreciate it.
I am not sure what your intension of 'cin >> "rate * price" ' is but it is not a valid line. cin is used for gathering input. Were you thinking cost = rate * price; This would give you totalCost = salesTax * price;

You should set your variables to some value so you don't get garbage in them like you did for rate. I believe it is good practice to set variables where they are declared if possible and not rely on their default values.
Last edited on
Topic archived. No new replies allowed.