Negative number check

The code on lines 44-53 is suppose to display a message when the user enter a negative number, however, when a correct positive number is entered the message is display again.

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include<iostream>
#include<cctype>
using namespace std;

int main()
{
   
 char carType;
 int A, B, C;
 char keepgoing;
 char condition; 
 double miles, per_miles,upgrade;
 double days, per_days,new_char;
 double price, fees, charges,discount, new_charges;


   
 do
 {
   
  do
  { 
    cout<<"Which car are you shopping for? (enter A, B, C)?"<<endl;
    cin>>carType;
      
    }while (carType != 'A' && carType != 'B' && carType != 'C' );
      
      

    cout<<"What condition? (S, O, or, P)"<<endl;
    cin>>condition;
     
    if ((condition !='S') || (condition !='O') || (condition !='P'));
     
    
    else
      cout<<"Please enter the correct response"<<endl;
    
    
    
    cout<<"How many miles?"<<endl;
    cin>>miles;
    
 do 
  {
   
  cout<<"How many days?"<<endl;
  cin>>days;
  
  cout<<"You enter a negative number,please try again."<<endl;
  
  
 }while (days < 0);
    
         cout.setf(ios::fixed);
         cout.setf(ios::showpoint);
         cout.precision(2);

      
      
         switch(carType)
      {
       
         case 'A':
         
         per_miles = miles * 0.10;
         per_days = days * 29.95;
         price = per_miles + per_days;
         
                  
         break;
         
         case 'B':
         
         per_miles = miles * 0.15;
         per_days = days * 35.95;
         price = per_miles + per_days;
         
         
              
         break;
         
         case 'C':
         
          per_miles = miles * 0.20;
         per_days = days * 39.95;
         price = per_miles + per_days;
         
                           
               
         break;
         
         default:
         cout<<"You entered an incorrect car choice"<<endl;
         }
         
         if(condition =='O')
         {
            fees = price * 0.10;
            price = price - fees;
         
         cout<<"The charges are?"<<price<<endl;
         
         
         
         }
         else if (condition == 'P')
         {
            fees = price * 0.10;
            price = price + fees;
                      
         cout<<"The charges are?"<<price<<endl;
         
        
         
         
         }
         else
         {
         cout<<"The charges are?"<<price<<endl;
         }
         
                    
               if (condition =='S')
               {
               fees = price * 0.10;
               new_charges = price + fees;
               discount = new_charges * 0.05;
               upgrade = new_charges - discount;
               
               cout<<"You may upgrade for a total cost of $"<<upgrade<<endl;
              }            
             else if(condition =='O')
             {
               discount = price * 0.05;
               upgrade = price - discount;
               
               cout<<"You may upgrade for a total cost of $"<<upgrade<<endl;
            }
            else
            {          
           cout<<"There are upgrades avialble"<<endl;
           
           }
         
               
         cout<<"Do you want another one (y/n)?"<< endl;
         cin>>keepgoing;
         
         }while (keepgoing == 'Y' || keepgoing == 'y');
         
         cout<<"Thank you for using this program. Goodbye."<<endl;
         }
         
                                        
You don't actually check the sign of the number in the 44-53 fragment.
Try to reproduce your problem with a simpler program
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using namespace std;

int main(){
   double days; //¿double?
   do
   {
   
      cout<<"How many days?"<<endl;
      cin>>days;
  
      cout<<"You enter a negative number,please try again."<<endl;
   }while (days < 0);
}
Also note, indentation.

If you follow that snip you should realize that you print the message of `negative number' before checking it.
Topic archived. No new replies allowed.