How to make a represent the letter a

My problem is simple. How can I go about making the value a represent the letter a. I need to make it so someone can type 'a' into the program and have it trigger my script for addition.
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
#include <iostream>
#include <math.h>
#include <cmath>
#include <stdio.h>
#include <istream>
using namespace std;

int main()
{
    
    {
           char a,s,x,r,p,d;
           a = "a";         
          cout << "Enter 'a' for Addition" << endl << "Enter 's' for Subtraction" << endl;
    cout << "Enter 'x' for Multiplication" << endl << "Enter 'd' for Division" << endl;
    cout << "Enter 'p' for Powers" << "Enter 'r' for Square Root" << endl;
    cout << "Please disragard the quotes" << endl;
    
    
    {
    if
    (a == "a")
    {
         float w, b, c,;
    c = w + b;
    cout << "Please enter the first number" << endl;
    cin >> w;
    cout << "Please enter the second number" << endl;
    cin >> b;
    cout << c << endl;
    system("PAUSE");
    }
}

That's not the whole thing, so keep in mind its missing some things.
So basically, how do I go about making my char a to equal a on the keyboard, and ect for s,x,r,p,d?
cin >> a;

You have to use single quotes for all of your comparisons because they are single characters and not a string.
Thank you. That fixed my issue. I have a new problem though. For some reason the answer to my equation is coming out as a weird number every time.I tried making w, b, c, doubles and integers, but its not coming out right. It's doing the same with my other equations (subtraction, multiplication...ect). Any idea?


EDIT: Nevermind. All I had to do was switch c = w + b; and put it AFTER the cin commands. Thanks again.
Last edited on
Topic archived. No new replies allowed.