Please help me with this simple C++ program!

Thread Starter

Allain Dominique Borno

Joined Oct 13, 2015
35
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;
}
 

WBahn

Joined Mar 31, 2012
24,854
Instead of writing an entire program and then discovering that it doesn't work, try building it up one feature at a time. That way when it stops working you have a very good idea where to look.
 

Thread Starter

Allain Dominique Borno

Joined Oct 13, 2015
35
Instead of writing an entire program and then discovering that it doesn't work, try building it up one feature at a time. That way when it stops working you have a very good idea where to look.
That is true. At first I was doing that, but then i kind of jumped around because I was excited. Do you see any noticeable errors though?
 

WBahn

Joined Mar 31, 2012
24,854
Yes, I see a few errors. Which you would have almost certainly found if you had worked on one function at a time.

Let's take your Input() function.

Write a main() that calls the Input() function and then, after it returns, prints out the value of cell, relays, and mins.

Once you figure out why, no matter what values you input, the output is zero for all of them you will be well on your way to figuring out your major problem.
 

Thread Starter

Allain Dominique Borno

Joined Oct 13, 2015
35
Yes, I see a few errors. Which you would have almost certainly found if you had worked on one function at a time.

Let's take your Input() function.

Write a main() that calls the Input() function and then, after it returns, prints out the value of cell, relays, and mins.

Once you figure out why, no matter what values you input, the output is zero for all of them you will be well on your way to figuring out your major problem.
Change of plans. I was able to fix all but one problem. I cannot store phone numbers bigger than the max 32 bit integer 2147... in int variable types. I am going to use a string or array. I need help doing that though. I need help with how to define a variable that the user can give input to scan into
 

WBahn

Joined Mar 31, 2012
24,854
How would you bring in a string if you asked the user for their name?

Treat their phone number the same way.
 
Top