How do you convert c++ to c# the old fashioned way

I have a assignment, (well tones really) but the problem is, I don't understand C# no really, I have no idea how to request input from the user at what given time, I thought the transition from some aspects of c++ would be easy but unfortunately Its not, even the most basic things, i can use a converter but I'm totally unsure why c# giving me grief.

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
  
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;
/*
Runs with out any hassles
*/

int main()

	{

        std::cout<<"Currency converter"<<std::endl;
	 // Declared variables
         double Au = 0.8, Us = 1.0;
	 double output1, input1, input2,  output2;
	 std::cout << "--------------------- "<<std::endl;
	 std::cout <<"Au to Us: $"<<std::flush;
	 cin >> input1;
	 output1 = Au / Us * input1;
	 output1 = Us / Au * input1;
	 
	 std::cout << "--------------------- "<<std::endl;
	 std::cout <<"$1 Aud to Us is $"<<output1<<std::endl;
	 std::cout << "--------------------- "<<std::endl;
	 std::cout <<"Us to Au: $"<<std::flush;
	 cin >> input2;
	 output2 = Us / Au * input2;
	 output2 = Au / Us * input2;  
	 std::cout << "--------------------- "<<std::endl;
	 std::cout << "$1 Us to Au is $"<<output2<<std::endl;
	 std::cout << "--------------------- "<<std::endl;
	     
		
	return 0;
}
//////////////////////////////////////////////////////////////////////////////////////

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


 /*Please dont change namespace, Dcoder 
 and class must not be public*/

 //Compiler version 4.0, .NET Framework 4.5
/*
Gives me grief and constant errors
*/

 namespace Dcoder
 {
 	public class Program
 	{
 		public static void Main(string[] args)
	{
std::cout<<<<std::endl;
     Console.WriteLine("Currency converter");
	 // Declared variables
     double Au = 0.8, Us = 1.0;
	 double output1, input1, input2,  output2;
	 Console.WriteLine("--------------------- ")
	 Console.readLine(input1);
	 Console.log()"Au to Us: $");
	 output1 = Au / Us * input1;
	 output1 = Us / Au * input1;
	 Console.WriteLine("--------------------- ");
	 Console.WriteLine("$1 Aud to Us is $" + output1);
	 Console.WriteLine("--------------------- ");
	 Console.WriteLine(input2);
	 Console.WriteLine("Us to Au: $");
	 output2 = Us / Au * input2;
	 output2 = Au / Us * input2;  
	 Console.WriteLine("--------------------- ");
	 Console.WriteLine("$1 Us to Au is $" + output2);
	 Console.WriteLine("--------------------- ");
	 Console.WriteLine("Us to Au: $");
	 Console.readkey();
	      }	
       }
 }
////////////////////////////////////////////////////////////////////////////////////
	      

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

/*
No idea, was advised to use it 
*/
 /*Please dont change namespace, Dcoder 
 and class must not be public*/

 //Compiler version 4.0, .NET Framework 4.5


 namespace Dcoder
 {
 	public class Program
 	{
 		public static void Main(string[] args)
 		{
 			Console.Write("Currency converter");
Console.Write("\n");
// Declared variables
double Au = 0.8;
double Us = 1.0;
double output1;
double output2;
double input1;
double input2;
Console.Write("--------------------- ");
Console.Write("\n");
//Tangiable software converter C++ TO C# CONVERTER TODO TASK: The cout 'flush' manipulator is not converted by C++ to C# Converter:
//ORIGINAL LINE: std::cout <<"Au to Us: $"<<std::flush;
Console.Write("Au to Us: $");
double input1 = Console.ReadLine();
output1 = Au / Us * input1;
//output1 = Us / Au * input1;

Console.Write("--------------------- ");
Console.Write("\n");
Console.Write("$1 Aud to Us is $");
Console.Write(output1);
Console.Write("\n");
Console.Write("--------------------- ");
Console.Write("\n");
//C++ TO C# CONVERTER TODO TASK: The cout 'flush' manipulator is not converted by C++ to C# Converter:
//ORIGINAL LINE: std::cout <<"Us to Au: $"<<std::flush;
Console.Write("Us to Au: $");
double input2 = Console.ReadLine();
output2 = Us / Au * input2;
//output2 = Au / Us * input2;  
Console.Write("--------------------- ");
Console.Write("\n");
Console.Write("$1 Us to Au is $");
Console.Write(output2);
Console.Write("\n");
Console.Write("--------------------- ");
Console.Write("\n");
 		}
 	}
 }
Last edited on
OK I fixed the input. Console.Readline reads a string. To convert it to a double use the Convert class.
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
using System;

/*
No idea, was advised to use it 
*/
/*Please dont change namespace, Dcoder 
and class must not be public*/

//Compiler version 4.0, .NET Framework 4.5


namespace Dcoder
{
  public class Program
  {
    public static void Main(string[] args)
    {
      Console.Write("Currency converter");
      Console.Write("\n");
      // Declared variables
      double Au = 0.8;
      double Us = 1.0;
      double output1;
      double output2;
      double input1;
      double input2;
      Console.Write("--------------------- ");
      Console.Write("\n");
      //Tangiable software converter C++ TO C# CONVERTER TODO TASK: The cout 'flush' manipulator is not converted by C++ to C# Converter:
      //ORIGINAL LINE: std::cout <<"Au to Us: $"<<std::flush;
      Console.Write("Au to Us: $");
      string buffer = Console.ReadLine();
      input1 = Convert.ToDouble(buffer);
      output1 = Au / Us * input1;
      //output1 = Us / Au * input1;

      Console.Write("--------------------- ");
      Console.Write("\n");
      Console.Write("$1 Aud to Us is $");
      Console.Write(output1);
      Console.Write("\n");
      Console.Write("--------------------- ");
      Console.Write("\n");
      //C++ TO C# CONVERTER TODO TASK: The cout 'flush' manipulator is not converted by C++ to C# Converter:
      //ORIGINAL LINE: std::cout <<"Us to Au: $"<<std::flush;
      Console.Write("Us to Au: $");
      buffer = Console.ReadLine();
      input2 = Convert.ToDouble(buffer);
      output2 = Us / Au * input2;
      //output2 = Au / Us * input2;  
      Console.Write("--------------------- ");
      Console.Write("\n");
      Console.Write("$1 Us to Au is $");
      Console.Write(output2);
      Console.Write("\n");
      Console.Write("--------------------- ");
      Console.Write("\n");
    }
  }
}

Run it and check if the results are correct.
Compilation failed: 3 error(s), 0 warnings


source_file.cs(17,4): error CS0103: The name `Au' does not exist in the current context
source_file.cs(25,16): error CS0103: The name `Au' does not exist in the current context
source_file.cs(37,23): error CS0103: The name `Au' does not exist in the current context


C# is pain in the arse.
Are you sure you copied everything?
Line 17 is only an opening brace.

C# is pain in the arse.

No it isn't - it's actually easier than C++ or Java
It's not for people who don't bother to learn the syntax and some rules.
string buffer = Console.ReadLine();
input1 = Convert.ToDouble(buffer);
output1 = Au / Us * input1

Personally I didn't think to approach it in this manner, (I still enjoy getting into the code, yes c# teaches you rules and I think that's good, I guess the teacher expected me to learn c# in one day before I wasn't sure how to convert a string to a international, especially with parse) anyways I would have used stod or stold, string over double but not sure in c++ 2011.

You passed in a buffer is it c# then continued on

buffer = Console.ReadLine();
input2 = Convert.ToDouble(buffer);
output2 = Us / Au * input2;



Ps, Au wasn't assigned to a double, I mean common it's not easy coding on a phone, the look the teacher gives me 😃


Here's some free hugs and cake.🎂🤗🤗🤗🤗🎂
Last edited on
Topic archived. No new replies allowed.