How to assign a value to a letter input

Hi, i'm very new to C++ and I am trying to write a program where a user chooses between two devices, one costing $90 and the other costing $95. The user inputs either w or s, indicating which device they want, and I want to be able to assign the value of either 90 or 95 to the respective device in order to later be able to calculate tax as well as a discount on a bulk order. Any help/suggestions/ideas would be greatly appreciated. Thank you.

#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;

double w = 90;
double s = 95;
int main(int argc, char const *argv[]) {
string hd_type;
cout << "Enter a hard drive type (w or s)";
cin >> hd_type;
cout << "You chose " + hd_type << endl;
return 0;
}// main
Have another variable, double cost;

Then,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const double cost_w = 90;
const double cost_s = 95;

double cost;
if (hd_type == "w")
{
    cost = cost_w ;
}
else if (hd_type == "s")
{
    cost = cost_s;
}
else
{
     // User didn't enter w or s
    cout << "Error\n";
    return 1;
}

// taxes
double total = cost * 1.08;
Last edited on
Topic archived. No new replies allowed.