I had to make a program that calculates how much you gain or loose in a stock markect. I have everything worked out excpet how to use char. I've looked it up but i don't understand anything. Can you help explain it to me?

// Project 6.4. Calculates how much money you have gained, or lost, with a stock.

#include <iostream>

using namespace std; 

float StockName, NumOfStocks, OpenValue, CloseValue, Total;

int main ()
    cout << "Please enter the name of the stock. \n" ;
    cin >> StockName;

    cout << "How many stocks do you own? \n" ;
    cin >> NumOfStocks;

    cout << "Please enter its opening value. \n" ; 
    cin >> OpenValue;

    cout << "Please enter its closing value. \n" ;
    cin >> CloseValue;

    Total = (CloseValue - OpenValue) * NumOfStocks ;

    if (Total > 0) 

    cout << "You have gained $" <<Total<< ".\n" ;

    else (Total < 0) ;

    cout << "You have lost $" <<Total<< ".\n" ;

    return 0;
4 Years
Discussion Span
Last Post by vicky30312

char is just like any other Data type. You can do:

char VariableB = 'B';

char K = 'K';

char Zero = '0';

char NULLS = '\0';

//A char is always 1 character in length. An array of chars is called a string:

char Str[] = {'T', 'R', 'I', 'U', 'M', 'P', 'H'};

//which is equivalent to:

string Str = "Triumph";

//You can change chars as well (Just like any other variable):

K = VariableB;

//You can also get user input into a char:

int main()
    char VariableChar;
    cout<<"Please enter the first Character of your first name: "<<endl;
    cin>> VariableChar;

//It can also be used in a switch case statement and be casted to an int.

int main()
    char A = 'A';
    cout<<"The ASCII value of character A is: << (int) A <<endl;

    char Choice = '0';
    cout<<"Please choose a letter from A - C: "<<endl;
    cin>> Choice;

        case 'A': cout<<"You chose A";

        case 'B': cout<<"You chose "B";

        case 'C': cout<<"You chose "C";

        default: cout<<"You didn't enter a character between A and C;

    if (Choice == 'A')
        cout<<"Choice was equivalent to character A.."endl;
        cout<<"Choice has an ASCII value of: "<< (int) Choice <<endl;

I figured it all out and now it works. Thank you c:

Edited by vicky30312

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.