#include <iostream>
usingnamespace 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>
usingnamespace 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;
}
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
#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;
}