Integer variable not working

This is a fairly simple program and everything was fine until i was asked to declare the variable "relays" as an integer after doing so the code does not give me the proper output but if i declare the variable as double it works just fine. what am i missing?

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
#include <iostream> //standard library for i/o
#include <string>
#include <iomanip>

using namespace std;

int main()
{
	string user_response = "y";
	string cell_num;
	double net_cost;
	double call_tax;
	double total_cost;
	double tax_rate = 0;
	int relays;
	int call_length;

	while (user_response == "y" || user_response == "Y")
	{
		//User Input
		cout << "Please input a cell phone number: ";
		cin >> cell_num;

		cout << "Please input the number of relay stations used: ";
		cin >> relays;

		cout << "\nPlease input the length in minutes of the call: ";
		cin >> call_length;

		
		
		//tax rate based on number of relays
		if ((relays >= 1) && (relays <= 5))
			tax_rate = .01;
		else if ((relays >= 6) && (relays <= 11))
			tax_rate = .03;
		else if ((relays >= 12) && (relays <= 20))
			tax_rate = .05;
		else if ((relays > 21) && (relays <= 50))
			tax_rate = .08;
		else if (relays > 50)
			tax_rate = .12;

		// callculations
		net_cost = ((relays / 50) * 0.40) * call_length;
		call_tax = net_cost * tax_rate;
		total_cost = net_cost + call_tax;

		//Output
		cout << "\nCell Phone:               " << cell_num;

		cout << "\nNumber of Relay Stations: " << relays;

		cout << "\nMinutes Used:             " << call_length; 

		// display cost with a 2 decimal places precision
		cout << setprecision(2) << fixed << "\nNet Cost:                 " << net_cost; 

		cout << setprecision(2) << fixed << "\nCall Tax:                 " << call_tax;

		cout << setprecision(2) << fixed << "\nTotal Cost of Call:       " << total_cost;
		
		cout << "\n\nWould you like to do another calculation (Y or N): \n" << endl;
		cin >> user_response;
	}

	return  0;
}
Last edited on
yup thanks for the help :)
@LastSeen
You can also do this:

 
static_cast <double> (relays / 50)
@gentleguy, don't be a prick

I don't see a problem with using static_cast, though his code should look more like
static_cast<double>(relays)/50;
If you're going to trash on someone, you should justify it.
@gentleguy
Wow, why are you flaming at me...
1. No problem using static_cast. You're assuming I don't know what value is affected... without even asking. You just... think? that I don't know?
2. I already know you can use other features besides static_cast. If I use one method over another does that mean I don't know the other method?
3. Absolute lie.... what kind of person lies that someone is their brother?? I'm not your brother. What disruption? You're taking it a bit far... disruption?? Are you sure you're an adult?
4. You also reported me... without a good reason. (I'm pretty sure it's you)

I'm not surprised you've been reported.

@JayhawkZombie
Everyone has their way of whitespace. I personally like to have spaces when using operators. But I wasn't sure how to use whitespace when using static_cast
Last edited on
(relays / 50.0) suffice (without extra cast).
@coder777
Never thought of that. That is also another way.
@gentleguy
You really shouldn't post something unrelated the to original post.
@gentleguy
So immature lol...
What are you saying... step brother?
Anyways I'm tired of this nonsense argument I will not reply anymore. Make your last reply.
Topic archived. No new replies allowed.