Dont know what is wrong with my code

Can someone please help me with this code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 #include <iostream>
using namespace std;
int main() {
	// This program calulates the unit price.
	// Written by: Joe Vardaman

	int Quantity;
	int UnitPrice;
	int TotalAmount = Quantity * UnitPrice;
	cout << "Please enter the Quantity desired";
		cin >> Quantity ;
	cout << "Please enter the Unit Price:";
		cin >> UnitPrice ;
	cout << "The Quantity desired is:", cout << Quantity;
	cout << "The Unit Price is:", cout << UnitPrice;
	cout << " The Total amount is:", cout << TotalAmount;
	return 0;
}
TotalAmount = Quantity * UnitPrice; should be after Quantity and Price. Fix:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 #include <iostream>
using namespace std;
int main() {
	// This program calulates the unit price.
	// Written by: Joe Vardaman

	int Quantity;
	int UnitPrice;
	int TotalAmount;
	cout << "Please enter the Quantity desired";
		cin >> Quantity ;
	cout << "Please enter the Unit Price:";
		cin >> UnitPrice ;
	cout << "The Quantity desired is:"; cout << Quantity;
	cout << "The Unit Price is:"; cout << UnitPrice;
	TotalAmount = Quantity * UnitPrice;
	cout << " The Total amount is:"; cout << TotalAmount;
	return 0;
}
Last edited on
The problem is that you try to use the variables Quantity and UnitPrice before they have been given their values. You will have better luck if you move line 9 and place it between lines 13 and 14.
ok i did that and this is what happens:
1>LINK : fatal error LNK1168: cannot open C:\Users\josep\OneDrive\Documents\Visual Studio 2015\Projects\ConsoleApplication4\Debug\ConsoleApplication4.exe for writing
i just restarted the program and now it says this:
fatal error LNK1169: one or more multiply defined symbols found
Can you paste your updated code? symplus's code works fine on cpp.sh
Last edited on
#include <iostream>
using namespace std;
int main() {
// This program calulates the unit price.
// Written by: Joe Vardaman

int Quantity;
int UnitPrice;
int TotalAmount;
cout << "Please enter the Quantity desired";
cin >> Quantity;
cout << "Please enter the Unit Price:";
cin >> UnitPrice;
cout << "The Quantity desired is:"; cout << Quantity;
cout << "The Unit Price is:"; cout << UnitPrice;
TotalAmount = Quantity * UnitPrice;
cout << " The Total amount is:"; cout << TotalAmount;
return 0;
}
It Worked! Thank you
Topic archived. No new replies allowed.