Problem with switch statement -Returning ANSCII codes

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
#include <iostream>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <conio.h>

using namespace std;


char display_Menu(char Choice)
{   cout << endl; 
    cout << " This  calculates the  monthly credit card bills for a customer ."; 
    cout << endl;
    cout << endl;
    char code;
    cout << " Customer Credit Rating:" << endl;
    cout << "    E - Excellent Credit" << endl;
    cout << "    A - Average Credit" << endl;
    cout << "    B - Below Average Credit" << endl;
    cout << "    S - Substandard Credit" << endl;
    cout << "    L - Exit Program" << endl;
    cout << endl;
    cout << endl;
    do{
    cout << "Enter choice from Menu above: ";
    cin >> Choice;
    cout << endl;
    Choice = toupper(Choice);
    code = Choice;
    }while ((code != 'E')&&(code!= 'A')&&(code!= 'B')&&(code!= 'S' ));
       
    return (Choice);
}
//I need this switch statement to return the rates instead of the ANSCII equivalent of the letters because I am trying to calculate the rates

double codes( double &codeChoice)
{

    
     const float TIME = 0.08;
    
     
     
     float rate;
     int choice;
     
    switch(choice){
    
 
    case 'E':
    case 'e':
    rate = TIME * 0.14;
    
    break;     
    case 'A':
    case 'a':
         rate = TIME *0.16;      
    break;
    
    case 'B':
    case 'b':
         rate = TIME *0.18;      
    break;
    
    case 'S':
    case 's':
         rate = TIME *0.16;      
    break;
    
    default:
          cout<< " Invalid credit code" <<endl;
    break;  
  }  
  return rate; 
   
} 
 
double money(double &Payment_Balance)
{ 
    char code; 
       
       if(code != 'E'){
    cout << "Enter your charge on the credit card: ";
    cin >> Payment_Balance;}
    if (Payment_Balance < 0)
    {
         cout << "Please enter positive value" << endl;
         cin >> Payment_Balance;
    }  
    return (Payment_Balance); 
    
      
}     

int main()
{
 char Choice;
 char credit_code;
 char creditDisplay, again; 
 double credit_Balance;

 double interest;
float interestCodes;
  do{
  cout <<fixed <<showpoint <<setprecision(2);   
     credit_code= display_Menu(creditDisplay);
     interestCodes =(credit_code);
     cout <<endl;
     cout<< "interestCodes = "<<interestCodes;
     cout<<endl;
     credit_Balance = money(credit_Balance);
     interest = interestCodes * credit_Balance;
 cout << "interest  = "<<interest;
     Choice = toupper(Choice);
     
   } while ((Choice == 'E') && (Choice== 'W') &&
    (Choice == 'D') && (Choice == 'S') &&(Choice == 'E'));
  

  cout<<endl<<endl;
  cout << "Press [enter] to exit" <<endl;
  cin.ignore(); //needed because of keyboard input
  cin.get();
  return 0;
}
There's no such thing as "ANSCII". There's the American National Standards Institute, and the American Standard Code for Information Interchange.
It is the Acronym. and it can be found in the index of any computer book and I am well aware of what they mean - but that was not the question .... The question was about the switch statement - Thank you if you can help ..if you can not help thanks anyway.
It is the Acronym.
No, it isn't. There's ANSI and ASCII. "ANSCII" doesn't exist.
It does now, 'cause I just invented it.

ANSCII: the American National Standard Code for International Innerspace.

Also "Innerspace" is a word meaning the opposite of "outer space".
First off, your code never calls the codes() function, so it is hard to know what you are doing to get bad output from it. BTW, line 45 declares an uninitialized variable, which you use on line 47. This will produce nonsense. Also, lines 50-52 are missing a break statement.

The problem is how you are getting input from the user.

When asking for character input, get a character.
1
2
3
4
5
6
char c;
cout << "Enter A or B: " << flush;
cin >> c;
cin.ignore( 1000, '\n' );
if (toupper( c ) == 'A') cout << "A-OK!\n";
else                     cout << "B is Best!\n";

When asking for a number, get a number:
1
2
3
4
5
6
double n;
cout << "Enter your favorite number: " << flush;
cin >> n;
cin.ignore( 1000, '\n' );
if (n < 10) cout << "Less than ten\n";
else        cout << "Not less than ten\n";

The type of a thing matters.

Hope this helps.
Thanks Duoas it helped I appreciate your help.
Topic archived. No new replies allowed.