Help me out Please!!!

So this is the question:
http://i59.tinypic.com/2vab4gp.jpg
and this is my code .. what's wrong please help???

#include <iostream>
using namespace std;
const float Bill_Amount = 1200; // Amount of Bill
const double Price = 120; // Value of Discount
const string Electronics = "1"; // First type of products
const string Food = "2"; // Second type of products
const string Others = "3"; // Third type of products

int main ()
{
float x1, x2, x3;
cout<< "Please enter number of types of products"<<endl;
cin>> x1, x2, x3;
double NewPrice = 0;


if ((x1=1) && (Bill_Amount >=1000))
cout<< "NewPrice = Price - (Price * 0.1)" << "NewPrice = Price - (Price * 0.08)"<<endl;
else

if ((x2=2) && (Bill_Amount >=600))
cout<< "NewPrice = Price - (Price * 0.06)" << "NewPrice = Price - (Price * 0.04)" <<endl;
else

if ((x3=3))
cout<< "NewPrice = Price - (Price * 0.02)" <<endl;
else
cout<< "NewPrice = Price" << endl;
return 0;

}
Last edited on
In your if statements, replace "x1=1" with "x1==1". You're assigning, not checking for equality.
did it. still wrong. I get the result like this:
http://i60.tinypic.com/1z883q.png
That would be because... that's what you're doing in your code? You're not setting NewPrice- you're just displaying the equation.
#include <iostream>
using namespace std;
const float Bill_Amount = 1200; // Amount of Bill
const double Price = 120; // Value of Discount
const string Electronics = "1"; // First type of products
const string Food = "2"; // Second type of products
const string Others = "3"; // Third type of products

int main ()
{
	float x1, x2, x3;
	cout<< "Please enter number of types of products"<<endl;
	cin>> x1, x2, x3;
    cout << "X1=" << x1 << endl;
    cout << "X2=" << x2 << endl;
    cout << "X3=" << x3 << endl;

	float NewPrice = 0;
	
	
	if ((x1==1) && (Bill_Amount >=1000))
	cout<< (NewPrice = Price - (Price * 0.1)) << (NewPrice = Price - (Price * 0.08))<<endl;
	else
	
	if ((x2==2) && (Bill_Amount >=600))
	cout<< (NewPrice = Price - (Price * 0.06)) << (NewPrice = Price - (Price * 0.04)) <<endl;
	else
	
	if  ((x3==3))
	cout<< (NewPrice = Price - (Price * 0.02)) <<endl;
	else
	cout<< (NewPrice = Price) << endl;
	cout<< NewPrice;
	return 0;
	



Got this result: wrong right?

http://i61.tinypic.com/4uuoo5.jpg
Read the assignment again. Look at the inputs. You aren't asking the user for the inputs required. You are supposed to input the product type and the bill amount.

Also, you're combining the calculation of the new price with the output. To make a clean algorithm, do these separately. In other words, the basic algorithm should be:
- prompt the user for the product type and bill amount.
- compute the discount amount.
- display the output.

Make sure that when you run the program with the inputs in the example, you get exactly the outputs in the example. Following the specifications exactly is an absolutely essential part of programming.
Topic archived. No new replies allowed.