Problem with Do Loop

I'm writing a program that outputs a value based on a value the user inputs. For example, if the user inputs a value from 0 to 0.35, the program triples the value and returns it. And if the user inputs a value from 0.36 to 0.50, the program doubles it, and so on until the user enters a value less than zero, which ends the program.

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
  // name : Sean Hwang
// date : 5/19/2015
/*
this program will display
using variables concept
*/
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;


void main()
{
	// define variables here
	double couponvalue = 0.0;
	double couponrealvalue = 0.0;



	do
	{
                // user inputs the coupon value here
		cout << "value of coupon is: " << endl;
		cin >> couponvalue;

                // does not compute correctly
		if (0 < couponvalue < 0.36){
			couponrealvalue = couponvalue * 3;
			cout << couponrealvalue;
		}

                // does not compute correctly
		if (0.36 <= couponvalue < 0.51){
			couponrealvalue = couponvalue * 2;
			cout << couponrealvalue;
		}

                // does not return anything at all
		if (0.51 <= couponvalue < 1.00){
			couponrealvalue = 1.00;
			cout << couponrealvalue;
		}

		if (couponvalue >= 1.00){
			couponrealvalue = couponvalue;
			cout << couponrealvalue;
		}

	} while (couponvalue > 0);

	// output
	cout << "The total value of the coupons is " << couponvalue << " dollars" << endl;
}


The problem I am having is that when I try to enter any value, it returns an incorrect value or no value at all.
Each comparison needs be be written out,

if (0 < couponvalue < 0.36)

Doesn't do what you think it does.

You need something like:

if (couponvalue > 0 && couponvalue < 0.36)

You've got some other things to iron out too, like the loop checking if coupon value is greater than zero after it's already processed it.

Good luck.
Last edited on
Thank you so much, the program checks properly now.
Topic archived. No new replies allowed.