case switch statment half working need help
Jan 31, 2015 at 6:33am UTC
was making a somewhat of a Binary to Hex convertor but only 10/15 cases work and the non working are in the middle; 0010, 0011, 0100, 0101, 0110, 0111;;
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
// Test Code.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <conio.h>
using namespace std;
int main(void )
{ int A;
cout << "Enter the binary starting with the MSB \n" ;
START:
cin >> A;
switch (A)
{
case 0000:
cout.width(25);
cout << "0\n" ;
goto START;
case 0001:
cout.width(25);
cout << "1\n" ;
goto START;
case 0010:
cout.width(25);
cout << "2\n" ;
goto START;
case 0011:
cout.width(25);
cout << "3\n" ;
goto START;
case 0100:
cout.width(25);
cout << "4\n" ;
goto START;
case 0101:
cout.width(25);
cout << "5\n" ;
goto START;
case 0110:
cout.width(25);
cout << "6\n" ;
goto START;
case 0111:
cout.width(25);
cout << "7\n" ;
goto START;
case 1000:
cout.width(25);
cout << "8\n" ;
goto START;
case 1001:
cout.width(25);
cout << "9\n" ;
goto START;
case 1010:
cout.width(25);
cout << "a\n" ;
goto START;
case 1011:
cout.width(25);
cout << "b\n" ;
goto START;
case 1100:
cout.width(25);
cout << "c\n" ;
goto START;
case 1101:
cout.width(25);
cout << "d\n" ;
goto START;
case 1110:
cout.width(25);
cout << "e\n" ;
goto START;
case 1111:
cout.width(25);
cout << "f\n" ;
goto START;
}
return 0;
}
Jan 31, 2015 at 7:48am UTC
Numbers started with zero are octal, not decimal.
10 != 010 = 8
Jan 31, 2015 at 8:12am UTC
figured it out thanks
Last edited on Jan 31, 2015 at 9:06am UTC
Jan 31, 2015 at 9:20am UTC
Jan 31, 2015 at 10:04am UTC
New to programing only way i could get it to repeat the case to solve multiple times; What statement should i be using?
Jan 31, 2015 at 2:30pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
int main(void )
{
int A;
cout << "Enter the binary starting with the MSB \n" ;
while (true ) {
cin >> A;
cout.width(25);
switch (A)
{
case 0:
cout << "0\n" ;
break ;
case 1:
cout << "1\n" ;
break ;
case 10:
cout << "2\n" ;
break ;
...
}
return 0;
}
}
Topic archived. No new replies allowed.