please critic my code

Below is a program that is supposed to print a customer statement after generating a 5 digit customer no , includes different functions to calculate carpet cost and labor costs .

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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
#include <time.h>
#include <stdlib.h>

using namespace std;
int main()
{
  string customerNo;
  string customerName;
  float roomLength;
  float roomWidth;
  float sellingPrice;
  float carpetCost;
  float labourCost;
  float discount;
  int carpetSize;

   cout.setf(ios::fixed);
   cout.precision(2);
   cout << "\nPlease enter the following information: ";
   cout << "\n Customer name: ";
   cin >> customerName;
   cout << "\n Customer number: ";
   cin >> customerNo;
   cout << "\n The length of the room: ";
   cin >> roomLength;
   cout << "\n The width of the room: ";
   cin >> roomWidth;
   cout << "\n The carpet selling price: ";
   cin >> sellingPrice;

   // call function calculateCarpetSize
   void CalculateCarpetSize (float length, float width);
   {
          float carpetSize;
          carpetSize = (float length * float width);
          return carpetSize ;
   }


// call function calculateCarpetCost
void CalculateCarpetCost (int carpetSize ,int 24 , float 0.14 );
{
    float carpetCost;
    carpetCost = (carpetSize * sellingPrice * 0.14)
 return carpetCost;
}
// call function calculateLabourCost
 float labourCost (float carpetSize , int 24);
{
 float labourCost;
    labourCost = (carpetSize * 24);
 return labourCost;
}

     bool qualifyForDiscount(customerNo);
     if (customerNo first number == 0)
        qualifyForDiscount == true ;

           // call function computeDiscount
           computeDiscount (carpetCost);
           {
            srand(time(0));
            discount = 00001 + rand () % 32767;
           }
     else
            discount = 0.0;
     return discount;

      // call function printCustomerStatement
      compute printCustomerStatement(string customerName,string customerNo,float carpetCost,float labourCost,float discount)
      {
      cout.setf(ios::fixed);
      cout << endl;
      cout << "CROSWELL CARPET STORE" << endl;
      cout << "STATEMENT" << endl;

      cout << "Customer Name   : ";
      cin >> customerName;
      cout << "Customer Number :";
      cin >> customerNo;


      cout << "Carpet Price    : ";
      cout << "Labour          : ";

      cout <<"Subtotal         : ";
      cout <<"Less Discount    : ";

      cout <<" Subtotal        : ";
      cout <<"Plus Tax         : ";
      Total <<" Total          : ";
  }

 return 0;
} // end main
Last edited on
1) As a C++ programmer you should use C++ names for headers.
http://www.cplusplus.com/reference/clibrary/#headers
1
2
3
4
5
6
7
// C language
#include <time.h>
#include <stdlib.h>

// C++ language
#include <ctime>
#include <cstdlib> 


2) Unlearn using namespace std; and use prefix std:: instead.
http://www.parashift.com/c++-faq/using-namespace-std.html

3) Using std::string without including the string header.
#include <string> // missing in your code

4) Defining functions inside another function, in your case in main().
Strictly speaking this isn't legal C++ code.
http://stackoverflow.com/questions/4324763/c-can-we-have-functions-inside-functions

These functions should be defined outside of the main() function.
CalculateCarpetSize()
CalculateCarpetCost()
labourCost()
printCustomerStatement()


5) Learn and be consistent in using an indentation style to make your code easier to read.
My personal suggestion: Allman style.
http://en.wikipedia.org/wiki/Indent_style

Does your code actually compile? And if yes, what compiler/IDE are you using? For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
     bool qualifyForDiscount(customerNo);
     if (customerNo first number == 0)
        qualifyForDiscount == true ;

           // call function computeDiscount
           computeDiscount (carpetCost);
           {
            srand(time(0));
            discount = 00001 + rand () % 32767;
           }
     else
            discount = 0.0;
     return discount;
thank you , you've given me a lot to work on
Topic archived. No new replies allowed.