There's a program I wrote in C, it works perfectly. When I tried to translate it into the language C# it was not compiling. The problem was that C# doesn't know the meaning of scanf ("%19s" , string1);
like in C.
I changed scanf
to:
string read;
do
{
read = Console.ReadLine();
}
while (read.Length <= 19);
it couldn't work properly. then i tried: to change it into:
string string1Input = Console.ReadLine();
It was working better but if
statements were not checked because I was getting all "sum"-s equaled to 0.
This is the program written translated into C#:
public static class GlobalMembersAnbanisRicxvitiMnishvneloba
{
static int Main()
{
string string1 = new string(new char[20]);
sbyte a = (sbyte)'a';
sbyte b = (sbyte)'b';
sbyte g = (sbyte)'g';
sbyte X = (sbyte)'X';
sbyte i = (sbyte)'i';
sbyte H = (sbyte)'H';
sbyte V = (sbyte)'V';
etc..
int rigi;
int sum = 0;
int sum2 = 0;
int sum3 = 0;
Console.Write(" my word is:\n");
string string1Input = Console.ReadLine();
for (rigi = 0; string1[rigi] != '\0'; rigi++)
{
if (string1[rigi] == a)
{
sum3 = sum3 + 1;
sum2 = sum2 + 1;
sum = sum + 1;
}
else
if (string1[rigi] == b)
{
sum3 = sum3 + 3;
sum2 = sum2 + 2;
sum = sum + 2;
}
etc...
} /* end for*/
if (string1[rigi-1]==i)
{
sum=sum-10; sum2=sum2-10; sum3=sum3-55;
}
Console.Write("sum is:");
Console.Write("{0:D}\n", sum);
Console.Write("sum2 is:");
Console.Write("{0:D}\n", sum2);
Console.Write("sum");
Console.Write("{0:D}\n", sum3);
return 0;
}
}
The idea of the prog is:
Program gives a numerical meaning to each of the letter of a word we type and adds this numbers to each other.
Question II: how to make
if (string1[rigi-1]==i)
{
sum=sum-10; sum2=sum2-10; sum3=sum3-55;
}
work?