C++ HELP

For my C++ class my teacher wanted us to create a dividing calculator, that we would use the define DBL figure's to create the division table outline that has the answer display on top and the dividend and divisor on the side and inside (below the answer. The promblem I am having is when i printf or cout the DBL's it just displays the numbers not the ascii's, I have tried it on reverse with the number and still doesn't display them. Below is the code I am using. Any other way that I could try displaying them?





#include <iostream>
#include <iomanip>
#include <conio.h>
#include "pch.h"

using namespace std;

#define DBL_CROSS 206 // ╬
#define DBL_UR 187 // ╗
#define DBL_UL 201 // ╔
#define DBL_LL 200 // ╚
#define DBL_LR 188 // ╝
#define DBL_TO_DBL_B_JOINT 202 // ╩
#define DBL_TO_DBL_T_JOINT 203 // ╦
#define DBL_TO_DBL_L_JOINT 204 // ╠
#define DBL_TO_DBL_R_JOINT 185 // ╣
#define DBL_TO_SIN_B_JOINT 207 // ╧
#define DBL_TO_SIN_T_JOINT 209 // ╤
#define DBL_TO_SIN_L_JOINT 199 // ╟
#define DBL_HORIZONTAL 205 // ═
#define DBL_VERTICAL 186 // ║

// Integer Division Problem Display Tool

int main() {

// Declare Variables
// Prompt User For Needed Inputs
// Perform Necessary Mathematical Calculations
// Display Results
// It's Over!

int a, b, r, q;
std::cout << "Enter a value for the dividend: ";
cin >> b;
cout << "Enter a value for the divisor: ";
cin >> a;
r = b % a;
q = b / a;
cout << q << " R " << r << endl;

}

#define is the old C way of making constants within your code. It is not type-aware, and has no idea it's supposed to interpret those numbers as text characters; it simply replaces the tokens with the given number. There's no point in using it in modern C++ for constants.

Note that those characters, strictly speaking, aren't ASCII, but are extended ASCII. I think what's actually printed out depends on whether or not the console is set to interpret the characters as extended ASCII (as opposed to Latin-1 or UTF-8, etc.). Regardless, it shouldn't hurt to make them be unsigned chars instead of just chars. I believe on Windows it will print what you expect by default, but I'm not sure about Mac/Linux.

Do this instead:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

#include <iostream>

const unsigned char DBL_CROSS = 206; // ╬
const unsigned char DBL_UR  = 187; // ╗
const unsigned char DBL_UL = 201; // ╔
const unsigned char DBL_LL = 200; // ╚
const unsigned char DBL_LR = 188; // ╝
const unsigned char DBL_TO_DBL_B_JOINT = 202; // ╩
const unsigned char DBL_TO_DBL_T_JOINT = 203; // ╦
const unsigned char DBL_TO_DBL_L_JOINT = 204; // ╠
const unsigned char DBL_TO_DBL_R_JOINT = 185; // ╣
const unsigned char DBL_TO_SIN_B_JOINT = 207; // ╧
const unsigned char DBL_TO_SIN_T_JOINT = 209; // ╤
const unsigned char DBL_TO_SIN_L_JOINT = 199; // ╟
const unsigned char DBL_HORIZONTAL = 205; // ═
const unsigned char DBL_VERTICAL = 186; // ║

int main()
{
    std::cout << DBL_UL << DBL_HORIZONTAL << DBL_HORIZONTAL << DBL_UR << '\n';
}

╔══╗


PS: In future topics, please note that a title like "C++ HELP" is not informative. A better title would be "Can't print ascii values in dividing calculator" or something like that.
Last edited on
here, I would have used an enum most likely. (Why: these look like they belong together and could use a 'we belong together grouping structure' which enum provides, a namespace would as well if you prefer).

Last edited on
Topic archived. No new replies allowed.