Please help, really struggling!!

program that prints customer bill. if the customeNo starts with "0" he is eligible for a discount... i have no idea where to begin...do i use void functions?

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
 #include <iostream>
using namespace std;
#include <iomanip>
#include <string>


int main()
{
    string customerNo, cusotmerName;
    float customerName, roomLength, roomWidth, sellingPrice, carpetCost, labourCost=24.00, discount;
    int carpetSize;
    
    cout << setprecision(2);
    cout << "\n please enter the following information: ";
    
    cout << "\n Customer name: " << customerName;
    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 >> sellingPrince;
    
    //call the function calculateCarpetSize
    //call the function calculateCarpetCost
    //call the function calculateLaborCost
    
    if(qualifyForDiscount(customerNo))
        //call function ComputeDiscount
        else
            disocunt = 0.0;
    //call function printCustomerStatement
    
    return 0;
    
}
Last edited on
That depends. Are there any more directions to your project? What does your customer bill consist of? How will those carpet calculations fit in to your bill, according to your professor or whatever book you're using?
What YFGHNG said.
But if your just checking if the customerNo starts with a zero I would setup your function to return a boolean.

//prototype
bool qualifyForDiscount(string customerNo);
well basically the statement should look like this

customer name :
customer number :
carpet price :
labour : subtotal :
less discount :
subtotal :
plus tax :
total :


so where my if statement is that should be bool instead?

and the discount is calculated before vat is added.

ive tried using a void to calculate ( roomLength * roomWidth)

where it says // call the function ......
those function can the be void functions.


Last edited on
So are you wanting to...
1) Get the customers input
2) Calculate the room size
3) Get the cost of the carpet for the size of room ( (roomL*roomW)*carpetPrice )
4) Add the labor
5) Check for discount, apply discount
6) Display something like an invoice?
yes... and then add tax 14% but that can not be applied to labour
so would i use a void function to calculateCarpetSize

and then call calculateCarpetSize in the main program

and then do it like that for all the //call function?
If you use void how are you going to get what that function just calculated? I would have the function return the calculation as a value.
When you list it out like that, I can tell you you're definitely gonna need to understand what functional return means.

http://en.cppreference.com/w/cpp/language/return

And judging from first look, you're gonna need a:
float calcRoomSize, float calcCarpetCost

The other variables, like subtotal can be like subtotal = carpetCost + labor + etc...

EDIT: I forgot to mention but @JamesDvorak mentioned it. I won't say anything about what parameters you're gonna assign to each function, but my advice is to keep them as simple as possible while still making logical sense.
Last edited on
yeah im still new to this thing.... il have a look at the link thanks.
Unless your using references in your function you wont be able to pull the calculations from a void function, it's kept in the scope of that function.

By using/creating a function like this.
1
2
3
float calculateCarpetPrice(float sellingPrice, float roomL, float roomW) {
	return (roomL * roomW) * sellingPrice;
}


You'll return whatever that output is as a float and you'll be able to use it inline.

Also check your spelling on your variables.
Topic archived. No new replies allowed.