Can anyone transfer this c# into c++

I accidentley wrote my entire program in c# and needed it into c++. Would anyone be able to help me and convert it to c++?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LAB4
{
class Program
{

static void Main(string[] args)
{
// initializing variables
char D1 = ' ',
D2 = ' ',
D3 = ' ',
D4 = ' ',
D5 = ' ',
D6 = ' ',
D7 = ' ',
D8 = ' ';
int returnValue;

// Loop that sends values by reference to ReadDials() method and compares the return value to see if they are valid.
do
{

returnValue = ReadDials(ref D1, ref D2, ref D3, ref D4, ref D5, ref D6, ref D7, ref D8);

if (returnValue == -5)
break;

switch (returnValue)
{
case -1:
Console.WriteLine("Error - An invalid character was entered");
break;
case -2:
Console.WriteLine("ERROR - Phone number cannot begin with 0.");
break;
case -3:
Console.WriteLine("ERROR - Phone number cannot begin with 555.");
break;
case -4:
Console.WriteLine("ERROR - Hyphen is not in the correct position.");
break;
default:
AcknowledgeCall(D1, D2, D3, D4, D5, D6, D7, D8);
break;
}
Console.WriteLine();

} while (true);
}

/* The ReadDials() method prompts the user to input a number, send the number to the
* ToDigit() method which converts letters to numbers and validates the input.
*/
static int ReadDials(ref char D1, ref char D2, ref char D3, ref char D4, ref char D5, ref char D6, ref char D7, ref char D8)
{
// local variables
int returnValue;

// prompts for user input
Console.Write("Enter a phone number (Q to quit): ");
D1 = Convert.ToChar(Console.Read());

// checks is input has been given to quit the program
if (D1.ToString().ToUpper() == "Q")
return -5;

// stores the input into the variables
D2 = Convert.ToChar(Console.Read());
D3 = Convert.ToChar(Console.Read());
D4 = Convert.ToChar(Console.Read());
D5 = Convert.ToChar(Console.Read());
D6 = Convert.ToChar(Console.Read());
D7 = Convert.ToChar(Console.Read());
D8 = Convert.ToChar(Console.ReadLine());

// beginning here each value is sent to the ToDigit() method to be convert to an upper case letter, then to a digit, and whether it is a valid digit.
returnValue = ToDigit(ref D1);
if(returnValue == -1)
return returnValue;

returnValue = ToDigit(ref D2);
if(returnValue == -1)
return returnValue;

returnValue = ToDigit(ref D3);
if(returnValue == -1)
return returnValue;

if(D4 != '-')
return -4;

returnValue = ToDigit(ref D5);
if(returnValue == -1)
return returnValue;

returnValue = ToDigit(ref D6);
if(returnValue == -1)
return returnValue;

returnValue = ToDigit(ref D7);
if(returnValue == -1)
return returnValue;

returnValue = ToDigit(ref D8);
if(returnValue == -1)
return returnValue;

if(D1 == '0')
return -2;

if(D1 == '5' && D2 == '5' && D3 == '5')
return -3;

return 0;
}

/* the ToDigit() method takes the user input and converts it to uppercase, then converts letters to numbers and then returns
*/
static int ToDigit(ref char digit)
{
// converts the variable to uppercase
digit = Char.ToUpper(digit);

// switch statement that converts the letters to numbers
switch (digit)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
break;
case 'A':
case 'B':
case 'C':
digit = '2';
break;
case 'D':
case 'E':
case 'F':
digit = '3';
break;
case 'G':
case 'H':
case 'I':
digit = '4';
break;
case 'J':
case 'K':
case 'L':
digit = '5';
break;
case 'M':
case 'N':
case 'O':
digit = '6';
break;
case 'P':
case 'Q':
case 'R':
case 'S':
digit = '7';
break;
case 'T':
case 'U':
case 'V':
digit = '8';
break;
case 'W':
case 'X':
case 'Y':
case 'Z':
digit = '9';
break;
default:
return -1;
}
return 0;
}

/* The AckowledgeCall() method takes the input from the user after it has been converted and verified
* and displays in on the console in numbers.
*/
static void AcknowledgeCall(char D1, char D2, char D3, char D4, char D5, char D6, char D7, char D8)
{
Console.WriteLine("Phone number Dialed: " + D1 + D2 + D3 + D4 + D5 + D6 + D7 + D8);
Console.WriteLine();
}
}
}
closed account (48T7M4Gy)
Wow, that was a bad accident, lucky it wasn't VB or Fortran.

How come you only picked up the blooper after writing so many lines. Usually that happens when cutting and pasting from some website, but obviously not in your case because you know what you are doing.

Our code conversion team is rushing into the office as we speak so stand by.
I was a zombie and wrote a c# program when I was supposed to be working on a c++ project. I'm in the Air Force and work a crazy amount of hours so anything i do on top of that I do in auto pilot.
closed account (48T7M4Gy)
Ok just look for the handle marked "Eject", lock the canopy down firmly, and pull.
closed account (48T7M4Gy)
https://social.msdn.microsoft.com/Forums/en-US/7512f1cb-b42d-4434-ac8d-4c0bc52cddbd/help-with-basic-c-function-homework-problem?forum=vcgeneral
Try this - it runs but I am not sure about the logic:
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// Test.cpp : main project file.

#include "stdafx.h"

using namespace System;
/* the ToDigit() method takes the user input and converts it to uppercase, then converts letters to numbers and then returns
*/
Int32 ToDigit(Char %digit)
{
  // converts the variable to uppercase
  digit = Char::ToUpper(digit);

  // switch statement that converts the letters to numbers
  switch (digit)
  {
  case '0':
  case '1':
  case '2':
  case '3':
  case '4':
  case '5':
  case '6':
  case '7':
  case '8':
  case '9':
    break;
  case 'A':
  case 'B':
  case 'C':
    digit = '2';
    break;
  case 'D':
  case 'E':
  case 'F':
    digit = '3';
    break;
  case 'G':
  case 'H':
  case 'I':
    digit = '4';
    break;
  case 'J':
  case 'K':
  case 'L':
    digit = '5';
    break;
  case 'M':
  case 'N':
  case 'O':
    digit = '6';
    break;
  case 'P':
  case 'Q':
  case 'R':
  case 'S':
    digit = '7';
    break;
  case 'T':
  case 'U':
  case 'V':
    digit = '8';
    break;
  case 'W':
  case 'X':
  case 'Y':
  case 'Z':
    digit = '9';
    break;
  default:
    return -1;
  }
  return 0;
}

/* The ReadDials() method prompts the user to input a number, send the number to the
* ToDigit() method which converts letters to numbers and validates the input.
*/
Int32 ReadDials(Char %D1, Char %D2, Char %D3, Char %D4, Char %D5, Char %D6, Char %D7, Char %D8)
{
  // local variables
  Int32 returnValue;

  // prompts for user input
  Console::Write("Enter a phone number (Q to quit): ");
  D1 = Convert::ToChar(Console::Read());

  // checks is input has been given to quit the program
  if (Char::ToUpper(D1) == 'Q')
    return -5;

  // stores the input into the variables
  D2 = Convert::ToChar(Console::Read());
  D3 = Convert::ToChar(Console::Read());
  D4 = Convert::ToChar(Console::Read());
  D5 = Convert::ToChar(Console::Read());
  D6 = Convert::ToChar(Console::Read());
  D7 = Convert::ToChar(Console::Read());
  D8 = Convert::ToChar(Console::ReadLine());

  // beginning here each value is sent to the ToDigit() method to be convert to an upper case letter, then to a digit, and whether it is a valid digit.
  returnValue = ToDigit(D1);
  if (returnValue == -1)
    return returnValue;

  returnValue = ToDigit(D2);
  if (returnValue == -1)
    return returnValue;

  returnValue = ToDigit(D3);
  if (returnValue == -1)
    return returnValue;

  if (D4 != '-')
    return -4;

  returnValue = ToDigit(D5);
  if (returnValue == -1)
    return returnValue;

  returnValue = ToDigit(D6);
  if (returnValue == -1)
    return returnValue;

  returnValue = ToDigit(D7);
  if (returnValue == -1)
    return returnValue;

  returnValue = ToDigit(D8);
  if (returnValue == -1)
    return returnValue;

  if (D1 == '0')
    return -2;

  if (D1 == '5' && D2 == '5' && D3 == '5')
    return -3;
  return 0;
}


/* The AckowledgeCall() method takes the input from the user after it has been converted and verified
* and displays in on the console in numbers.
*/
void AcknowledgeCall(Char D1, Char D2, Char D3, Char D4, Char D5, Char D6, Char D7, Char D8)
{
  Console::WriteLine("Phone number Dialed: " + D1 + D2 + D3 + D4 + D5 + D6 + D7 + D8);
  Console::WriteLine();
}

int main()
{
  // initializing variables
  Char D1 = ' ',
    D2 = ' ',
    D3 = ' ',
    D4 = ' ',
    D5 = ' ',
    D6 = ' ',
    D7 = ' ',
    D8 = ' ';
  int returnValue;

  // Loop that sends values by reference to ReadDials() method and compares the return value to see if they are valid.
  do
  {

    returnValue = ReadDials(D1, D2, D3, D4, D5, D6, D7, D8);

    if (returnValue == -5)
      break;

    switch (returnValue)
    {
    case -1:
      Console::WriteLine("Error - An invalid Character was entered");
      break;
    case -2:
      Console::WriteLine("ERROR - Phone number cannot begin with 0.");
      break;
    case -3:
      Console::WriteLine("ERROR - Phone number cannot begin with 555.");
      break;
    case -4:
      Console::WriteLine("ERROR - Hyphen is not in the correct position.");
      break;
    default:
      AcknowledgeCall(D1, D2, D3, D4, D5, D6, D7, D8);
      break;
    }
    Console::WriteLine();

  } while (true);

  return 0;
}
closed account (48T7M4Gy)
Try this - it runs
Yeah sure, so does a tap. It's not C++. I don't really care all that much but why encourage this crap from this OP moron when there are decent ppl to help.
Topic archived. No new replies allowed.