Im using xcode to write my program. Every time I build and run the program it will do everything fine, until the end. It keeps giving me an answer of 0 no matter what i put. Need help to figure out what im doing wrong thanks in advance.

//price_converter

#include <iostream>
#include <string>
#include <cmath>;
using namespace std;

int main()
{
	float price, total, tax;
	int quantity;
	string product;
	tax = .0875;
	total = price * quantity * tax;
	
	cout << "what are you buying?\n";
	cin >> product;
	
	cout << "how much does it cost?\n";
	cin >> price;
	
	cout << "how many are you buying?\n";
	cin >> quantity;
	
	if(quantity <= 0)
	{
		cout << "you have to buy something";
		return 0;
	}
	
	cout << "your total for your\n" << product << " is\n" <<  total;
	
	return 0;
	
}

You're trying to calculate before you get the input. This line should go after you get the input to assign a value to price and quantity.

total = price * quantity * tax;

thanks for your reply really makes more sense now:)

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.