Void functions

I have to create a program using three void functions and a value returning function. I have been working on this and as far as I have gotten is the code below.

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

//function prototype
void getInput
void calcTotComm
void displayComm

int main()
{
//declare variables
const double comm = 0.10;
int totalComm = 0.0;
double sales = 0.0;

cout << "Enter sales amount (-1 to stop): " << endl;
cin >> sales;

while (sales >= 0)
{
cout << "Enter next sales amount (-1 to stop): " << endl;
cin >> sales;

//calculate total commission
calcSales

cout << fixed << setprecision(2);

//call functions
getInput
calcTotComm
displayComm


I know this is no where near complete. I am suppose to enter sales amounts until I hit the negative number to stop. The it is supposed to calculate the amounts and give the total commission. Am I going in the right direction? I know there is supposed to be a loop inside the function, but I don't know if what I have already done is right.
Last edited on
In your current code you have each sale is being saved in the same variable so only the final entered sale will actually be saved in that variable. Consider using an array to save each individual sale. Or if you are not interested in the sales themselves and only interested in the total then add each new sale to the total sale saved instead of trying to save each sale individually.

A few other minor things to change:
1. You're prototypes and function calls are not functions at this point, they need parameters after the name within parentheses even if they have no parameters they still need to be included. Although since all of your functions are void and you need the data to run the other functions your program is going to need parameters.
2. Close off your loop and main function with ending brackets
3. setprecision is a data manipulator that is used to alter output so it belongs within your displayComm function not within the main function
You will not need to perform any calculations in the main(), because the calculations will be defined in the function definition so all you need to do is create the proper variable and assign/call a function to it.

like:
totalComm = calcTotComm(parameter 1,parameter 2);

From what I can tell the only function that is void is the display function. If a function returns a value, I believe it is not void.
Topic archived. No new replies allowed.