Dont know what is wrong with my code

Jan 26, 2017 at 11:32pm
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;
}
Jan 26, 2017 at 11:43pm
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 Jan 27, 2017 at 1:11am
Jan 26, 2017 at 11:46pm
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.
Jan 26, 2017 at 11:53pm
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
Jan 27, 2017 at 12:00am
i just restarted the program and now it says this:
fatal error LNK1169: one or more multiply defined symbols found
Jan 27, 2017 at 12:23am
Can you paste your updated code? symplus's code works fine on cpp.sh
Last edited on Jan 27, 2017 at 12:25am
Jan 27, 2017 at 12:25am
#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;
}
Jan 27, 2017 at 12:50am
Jan 27, 2017 at 12:52am
It Worked! Thank you
Topic archived. No new replies allowed.