Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   help!! (http://www.go4expert.com/forums/help-t16223/)

clot 17Feb2009 08:40

help!!
 
this is the question which I had an assignment from my professor.

Sample Input/Output:
1. Cars in stock for brand: Psagal3
Quantity on hand: 10

2. Cars in stock for brand: WiralS
Quantity on hand: 13

3. Cars in stock for brand: Merd2O
Quantity on hand: 5

4. Cars in stock for brand: Psagal5
Quantity on hand: 23

5. Cars in stock for brand: PAero 13
Quantity on hand: 38

6. Cars in stock for brand: PAero 18
Quantity on hand: 4

7. Cars in stock for brand: HondaC
Quantity on hand: 20

8. Cars in stock for brand: HondaA
Quantity on hand: 25

9. Cars in stock for brand: BMW98
Quantity on hand: 17

10. Cars in stock for brand: Merd3O
Quantity on hand: 27

*****************************
Which brand was sold? Psaga15
How many cars in sale? 6

Which brand was sold? BMW98
How many cars in sale? 7

Which brand was sold? Merd3O
How many cars in sale? 5

Which branch was sold? –l

******************************************
* DAILY REPORT *
******************************************
Brand code : Psagal3
Inventory at day start : 10
Total sales : 0
Inventory at day end : 10
Sales as a percentage of inventory : 0.00%

Brand code : Wiral5
Inventory at day start : 13
Total sales : 0
Inventory at day end : 13
Sales as a percentage of inventory : 0.00%

Brand code : Merd2O
Inventory at day start : 5
Total sales : 0
Inventory at day end : 5
Sales as a percentage of inventory : 0.00%

Brand code : Psagal5
Inventory at day start : 23
Total sales : 6
Inventory at day end : 17
Sales as a percentage of inventory : 26.09

Brand code : PAerol3
Inventory at day start : 38
Total sales : 0
Inventory at day end : 38
Sales as a percentage of inventory : 0.00%

Brand code : PAerol8
Inventory at day start : 4
Total sales : 0
Inventory at day end : 4
Sales as a percentage of inventory : 0.00%

Brand code : HondaC
Inventory at day start : 20
Total sales : 0
Inventory at day end : 20
Sales as a percentage of inventory : 0.00%

Brand code : HondaA
Inventory at day start : 25
Total sales : 0
Inventory at day end : 25
Sales as a percentage of inventory : 0.00%

Brand code : BMW98
Inventory at day start : 17
Total sales : 7
Inventory at day end : 10
Sales as a percentage of inventory : 41.18%

Brand code : Merd3O
Inventory at day start : 27
Total sales : 5
Inventory at day end : 22
Sales as a percentage of inventory : 15.52%



So here's my source code:

Code:

#include <iostream>
using namespace std;

struct Car_Sales
{
        char bstock[15];
        int quantity;
        int bsold,x;
} cs[10];

void main()
{
        for (int x=0; x<10; x++)
        {
                cout << "Cars in stock for brand: ";
                cin >> cs[x].bstock;
                cout << "Quantity on hand: ";
                cin >> cs[x].quantity;
                cout << endl;
        }

        char btemp[15];
        do
        {
                int found = 0;
                cout << "Which brand was sold? ";
                cin >> btemp;


                if (strcmp (btemp, "-1") == 0)
                        break;

                for (int x=0; x<10; x++)
                        if (strcmp (btemp, cs[x].bstock) == 0)
                        {
                                found = 1;
                                cout << "How many cars in sale? ";
                                cin >> cs[x].bsold;
                                break;
                        }
               
                if (found == 0)
                        cout << "No brand was found in stock.\n";
        } while (strcmp (btemp, "-1") != 0);

        cout << "******************************************\n";
        cout << "  * DAILY REPORT *\n";
        cout << "******************************************\n";

        float sperc;
        for (int x=0; x<10; x++)
        {       
                sperc=(cs[x].bsold*100)/(cs[x].quantity*100);
                cout << "Brand Code: \t\t\t\t" << cs[x].bstock << endl;
                cout << "Inventory At Day Start: \t\t" << cs[x].quantity << endl;
                cout << "Total Sales: \t\t\t\t" << cs[x].bsold << endl;
                cout << "Inventory At Day End: \t\t\t" << cs[x].quantity-cs[x].bsold << endl;
                cout << "Sales As Percentage Of Inventory: \t" << sperc << "%" << endl;
                cout << endl;
        }
        system ("pause");
}

i have no idea how to solve this issue.

can anyone provide me simpler source code?
cause this code which i can very hardly understand

xpi0t0s 17Feb2009 15:49

Re: help!!
 
The code is not difficult to follow and it is hard to see how it could be simplified further. What part(s) are you struggling to understand?

Also you forgot to state what the problem was, i.e. the issue you're trying to solve.

shabbir 17Feb2009 16:26

Re: help!!
 
Quote:

Originally Posted by xpi0t0s (Post 43024)
The code is not difficult to follow and it is hard to see how it could be simplified further. What part(s) are you struggling to understand?

Also you forgot to state what the problem was, i.e. the issue you're trying to solve.

It does not look good but you also did not gave a title which would be helpful


All times are GMT +5.5. The time now is 01:20.