I have two main problems. When I try to give my phone number for the program, it runs through all the functions at once, when it is supposed to only take my phone number, then go through the questions. If i type a random number that is relatively short, it'll go through.
But then even when it goes through, later when the program is supposed to print all the info based on some math, it prints all of the values as 0s when that is not what it's supposed to do.
Here is my code! What am I doing wrong? The compiler has no errors at all. I'm using microsoft visual studio 2013 for C++
Description:
In this assignment a call management system is implemented. The program used three functions:
input, output, and process. The function input gets input from the user, the function process performs
the necessary calculations, and the function output prints the results.
*/
#include <iostream>
#include <string>
using namespace std;
//Function Prototypes
void Input(int, int, int);
void Output(int, int, int, double, double, double);
void Process(int, int, double, double, double, double);
///*************************************************************************************
//Name: Input
//Basically takes 3 int variables and reads user input into them (cell, relays and mins).
//*************************************************************************************
void Input(int cell, int relays, int mins)
{
cout << "Hello!\n\nPlease enter your cell number:";
cin >> cell;
cout << "Please enter the number of relay stations:";
cin >> relays;
cout << "Please enter the length of the call in minutes:";
cin >> mins;
}
///*************************************************************************************
//Name: Output
//After the processing function is done doing the math, this function displays the results and user inputs
//Cell, relays, mins, tax, nCost, cost.
//*************************************************************************************
void Output(int cell, int relays, int mins, double tax, double nCost, double cost)
{
cout << "**************************************\n";
cout << "Cell Phone Number:";
cout << cell;
cout << "\n**************************************";
cout << "\nNumber of Relay Stations:";
cout << relays;
cout << "\nLength of Call (Minutes):";
cout << mins;
cout << "\nNet Cost of Call:";
cout << nCost;
cout << "\nTax of Call:";
cout << tax;
cout << "\nTotal Cost of Call:";
cout << cost;
}
///*************************************************************************************
//Name: Process
//This function does all the calculations to calculate taxRate, nCost, tax and cost.
//It needs relays, mins, taxRate, tax, nCost and cost to do this.
//*************************************************************************************
void Process(int relays, int mins, double taxRate, double tax, double nCost, double cost)
{
if (relays >= 1 && relays <= 5)
{
taxRate = .01;
nCost = (relays / 50.0*.40*mins);
tax = nCost*taxRate / 100;
cost = nCost + tax;
}
if (relays >= 6 && relays <= 11)
{
taxRate = .03;
nCost = (relays / 50.0*.40*mins);
tax = nCost*taxRate / 100;
cost = nCost + tax;
}
if (relays >= 12 && relays <= 20)
{
taxRate = .05;
nCost = (relays / 50.0*.40*mins);
tax = nCost*taxRate / 100;
cost = nCost + tax;
}
if (relays >= 21 && relays <= 50)
{
taxRate = .08;
nCost = (relays / 50.0*.40*mins);
tax = nCost*taxRate / 100;
cost = nCost + tax;
}
if (relays >50)
{
taxRate = .12;
nCost = (relays / 50.0*.40*mins);
tax = nCost*taxRate / 100;
cost = nCost + tax;
}
}
int main()
{
//Here is where the program runs. This is where all variables are declared so that the program/functions can use them.
int cell=0, relays=0, mins=0;
double taxRate=0, tax=0, nCost=0, cost=0;
char choice='n';
//User can do multiple calculations until "choice" = n.
do
{
Input(cell, relays, mins);
Process(relays, mins, taxRate, tax, nCost, cost);
Output(cell, relays, mins, tax, nCost, cost);
cout << "\n\nWould you like to do another calculation (enter y or n):";
cin >> choice;
} while (choice == 'y' || choice == 'Y');
cout << "Thank you and have a nice day!";
return 0;
}
But then even when it goes through, later when the program is supposed to print all the info based on some math, it prints all of the values as 0s when that is not what it's supposed to do.
Here is my code! What am I doing wrong? The compiler has no errors at all. I'm using microsoft visual studio 2013 for C++
Description:
In this assignment a call management system is implemented. The program used three functions:
input, output, and process. The function input gets input from the user, the function process performs
the necessary calculations, and the function output prints the results.
*/
#include <iostream>
#include <string>
using namespace std;
//Function Prototypes
void Input(int, int, int);
void Output(int, int, int, double, double, double);
void Process(int, int, double, double, double, double);
///*************************************************************************************
//Name: Input
//Basically takes 3 int variables and reads user input into them (cell, relays and mins).
//*************************************************************************************
void Input(int cell, int relays, int mins)
{
cout << "Hello!\n\nPlease enter your cell number:";
cin >> cell;
cout << "Please enter the number of relay stations:";
cin >> relays;
cout << "Please enter the length of the call in minutes:";
cin >> mins;
}
///*************************************************************************************
//Name: Output
//After the processing function is done doing the math, this function displays the results and user inputs
//Cell, relays, mins, tax, nCost, cost.
//*************************************************************************************
void Output(int cell, int relays, int mins, double tax, double nCost, double cost)
{
cout << "**************************************\n";
cout << "Cell Phone Number:";
cout << cell;
cout << "\n**************************************";
cout << "\nNumber of Relay Stations:";
cout << relays;
cout << "\nLength of Call (Minutes):";
cout << mins;
cout << "\nNet Cost of Call:";
cout << nCost;
cout << "\nTax of Call:";
cout << tax;
cout << "\nTotal Cost of Call:";
cout << cost;
}
///*************************************************************************************
//Name: Process
//This function does all the calculations to calculate taxRate, nCost, tax and cost.
//It needs relays, mins, taxRate, tax, nCost and cost to do this.
//*************************************************************************************
void Process(int relays, int mins, double taxRate, double tax, double nCost, double cost)
{
if (relays >= 1 && relays <= 5)
{
taxRate = .01;
nCost = (relays / 50.0*.40*mins);
tax = nCost*taxRate / 100;
cost = nCost + tax;
}
if (relays >= 6 && relays <= 11)
{
taxRate = .03;
nCost = (relays / 50.0*.40*mins);
tax = nCost*taxRate / 100;
cost = nCost + tax;
}
if (relays >= 12 && relays <= 20)
{
taxRate = .05;
nCost = (relays / 50.0*.40*mins);
tax = nCost*taxRate / 100;
cost = nCost + tax;
}
if (relays >= 21 && relays <= 50)
{
taxRate = .08;
nCost = (relays / 50.0*.40*mins);
tax = nCost*taxRate / 100;
cost = nCost + tax;
}
if (relays >50)
{
taxRate = .12;
nCost = (relays / 50.0*.40*mins);
tax = nCost*taxRate / 100;
cost = nCost + tax;
}
}
int main()
{
//Here is where the program runs. This is where all variables are declared so that the program/functions can use them.
int cell=0, relays=0, mins=0;
double taxRate=0, tax=0, nCost=0, cost=0;
char choice='n';
//User can do multiple calculations until "choice" = n.
do
{
Input(cell, relays, mins);
Process(relays, mins, taxRate, tax, nCost, cost);
Output(cell, relays, mins, tax, nCost, cost);
cout << "\n\nWould you like to do another calculation (enter y or n):";
cin >> choice;
} while (choice == 'y' || choice == 'Y');
cout << "Thank you and have a nice day!";
return 0;
}