C++ code using switch that prints seven segment numbers

Hey i need help with a code that inputs a number and outputs the corresponding seven segment number
my teacher said:
Use seven Boolean variables for each number( top, middle, bottom, top_left, top_right, bottom_left and bottom_right) Use a switch statement to assign appropriate values for each number from 0 to 9. Then use another control structure to print the proper segments of a number entered.

i'm a little confused here
any help would be great thanks
7 boolean values? but there are number from 0-9, aren't you missing left, and right?
I think you need to enter a number like 159, and you loop through the string and output the thing, but your teacher wants bools, and a class, and wants you to output it based off the bools, and ignore left and right for some reason.
7 boolean values for each segment of the number
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
#include <iostream>
using namespace std;

struct Display
{
   bool T, M, B, TL, TR, BL, BR;
};

//=====================================================================


Display setSegments( int n )               // n should be 0 to 9
{
   Display d{1,1,1,1,1,1,1};               // start with all segments ON

   switch ( n )
   {
      case 0: d.M                              = 0;   break;
      case 1: d.T  = d.M  = d.B  = d.TL = d.BL = 0;   break;
      case 2: d.TL = d.BR                      = 0;   break;
      case 3: d.TL = d.BL                      = 0;   break;
      case 4: d.T  = d.B  = d.BL               = 0;   break;
      case 5: d.TR = d.BL                      = 0;   break;
      case 6: d.T  = d.TR                      = 0;   break;
      case 7: d.M  = d.B  = d.TL = d.BL        = 0;   break;
      case 8:                                     ;   break;
      case 9: d.B  = d.BL                      = 0;   break;
      default: cout << "ERROR\n";
   }

   return d;
}


//=====================================================================


void draw( Display d )
{
   const char S = ' ', H = '-', V = '|';
   const char v[] = { S, V };
   const char h[] = { S, H };

   cout << S       << h[d.T] << S       << '\n'
        << v[d.TL] << S      << v[d.TR] << '\n'
        << S       << h[d.M] << S       << '\n'
        << v[d.BL] << S      << v[d.BR] << '\n'
        << S       << h[d.B] << S       << '\n';
   cout << '\n';
}


//=====================================================================


int main()
{
   for ( int n = 0; n < 10; n++ ) draw( setSegments( n ) );
}


//=====================================================================  
Last edited on
Topic archived. No new replies allowed.