project help

project says
1. have user input number that is greater then 0 and add them to total
2. exit loop on -99
3. once out of loop calculate tax due on total and calculate the average cost of items entered.
4. display total of the items, average of the items, amount of tax due, total for transaction.

I am having trouble getting the average cost because its in a function and i can only return the total not the count (to find the average)????

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
98
99
100
101
102
103
104
105
  #include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
//*******************************Prototypes********************************

float testInput (float value, float endValue, string prompt);
float numberTotal (string prompt);



// *********************************mainline************************************


int main(){
    float endValue, value, total, tax, taxDue, averageItem;
    int number, square, cube, count;
    
    
    value = testInput (0, 50,"Please pick a starting number between 1 and 50: " );
    endValue = testInput (value, 100, "Please enter a ending number that is greater then your starting number but less than 100: ");

    
    cout << "Number"<<setw(10) << "Squared" << setw(10) << "Cubed"<< endl;
    
    for (number = value; number<= endValue; number++){
        square = number * number;
        cube = number * number * number;
       
        cout<< number<< " ";
        cout << setw(10)<< square<< " ";
        cout <<setw(10)<<cube << " ";
        cout <<endl;
    
    }
    
    cout<<endl;
    
    
    total = numberTotal ( "Enter a number to add or hit -99 to exit: ");
    cout << endl;
    cout << endl;
    //Calculate tax due on sale
    
    tax=(total * .0625); //tax rate is 6.25%
    taxDue = tax + total; // total due
    averageItem = total / count; // average
    cout << fixed << setprecision(2);
    cout << "Total number of items entered : " <<right<< setw(9)<< total <<endl;
    cout << "Average of the items : " << endl;
    cout << "Ammount of tax due : " << right << setw(20)<< tax << endl;
    cout << "Total for the transaction : " <<right<<setw(13)<< taxDue << endl;
    
    
    

    
    
        return 0;
    }
//*********************************Functions*******************************
float testInput (float value, float endValue, string prompt){
    float number;
    do {
        cout << prompt;
        cin >> number;
 // Then get an error message to occur
        
        
        if (number <= value || number > endValue ) {
            cout << "Error please enter a number that is between" << value << " and " << endValue << endl;
        }
    
    }
    while (number <= value || number > endValue);
        return number;
}

float numberTotal (string prompt){
    float num;
    float total;
    int count = 0;
    
    
    do {
        cout << prompt;
        cin >> num;
        
        if (num > 0){
        total = num + total;
            count= count +1;
            cout << "The total is " << total << endl;
            cout << "The count is " <<count<< endl;
            
        }
        
        }
    
    
    while(num !=-99);

    
    return total, count;
}
Last edited on
Topic archived. No new replies allowed.