HAve problem of C++ programming
Oct 2, 2010 at 1:28am UTC
Sorry for bothering you. Do you have some idea about the below code? I cannot print the company name when I run the program. Would you please let me know which part is wrong and I can modify the code. Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#include <iostream>
float CostPrice;
float NumOfProdCreated;
float SellPrice;
float NumOfProSold;
float CompanyName;
float TotalCost;
float TotalRevenue;
float Profit;
float Loss;
using namespace std;
int main()
{
cout << "\n" ;
cout << "How much did you buy the product for?\n" ;
cin >> CostPrice;
cout << "\n" ;
cout << "How many proudct did you buy?\n" ;
cin >> NumOfProdCreated;
cout << "\n" ;
cout << "How much did you sell the product for?\n" ;
cin >> SellPrice;
cout << "\n" ;
cout << "How many product did you sell?\n" ;
cin >> NumOfProSold;
cout << "\n" ;
cout << "What's the name of company?\n" ;
cin >> CompanyName;
TotalCost = CostPrice*NumOfProdCreated;
TotalRevenue = SellPrice*NumOfProSold;
Profit = TotalRevenue-TotalCost;
Loss = TotalCost-TotalRevenue;
cout << "\n" ;
cout << CompanyName;
cout << "\n" ;
if (TotalCost < TotalRevenue) {
cout << "You got " << Profit << " dollars in profit\n" ;
}
if (TotalCost > TotalRevenue) {
cout << "You got " << Loss << " dollars in loss\n" ;
}
return 0;
}
Oct 2, 2010 at 1:42am UTC
Your company name is a float make it something else, maybe a string =)
Oct 2, 2010 at 8:29am UTC
ultifinitus means you should:
1 2 3
#include<string> //include this header AND
string companyName;//Declare Company name like this
Oct 2, 2010 at 12:46pm UTC
Hi all,
I have done it. Thnak you so much!!
Topic archived. No new replies allowed.