How would the conversion of this algorithm from c to c #?

-4

How can I convert this algorithm from c to c #?

int main () {
        char nome[50];
        float LIM=20, soma=0.0, media, mediaTurma;
        float a, b, c, d, e, f, g, h, i, j; 
        int x, y;
        for (x=0; x<=LIM;x++){
            printf("Digite o nome do aluno:\t");
            scanf("%s", nome);
            printf("\nNota 1:");
            scanf("%f", &a);
            printf("Nota 2:");
            scanf("%f", &;  
            printf("Nota 3:");
            scanf("%f", &c); 
            printf("Nota 4:");
            scanf("%f", &d); 
            printf("Nota 5:");
            scanf("%f", &e); 
            printf("Nota 6:");
            scanf("%f", &f); 
            printf("Nota 7:");
            scanf("%f", &g); 
            printf("Nota 8:");
            scanf("%f", &h); 
            printf("Nota 9:");
            scanf("%f", &i); 
            printf("Nota 10:");
            scanf("%f", &j);
            soma=a+b+c+d+e+f+g+h+i+j;
            media=soma/10;
                   if (media>=5) {
                          printf("Aluno aprovado! Media %f\n", media);
                   }
                   else {
                          printf("Aluno reprovado! Media %f\n", media);
                   }
            printf("-----------------------------\n\n");
            }
      system("PAUSE");    
      return 0;
    }
    
asked by anonymous 17.06.2017 / 01:35

3 answers

0

A tip: The code is very poorly written, I recommend doing with arrays, but ok. Translated to C # by you, just copy and paste.

public static void Main()
{
    double soma=0, media;
    double a, b, c, d, e, f, g, h, i, j;
    for (int x=0; x<=20;x++){
        Console.WriteLine("Digite o nome do aluno:\t");
        string nome = Console.ReadLine();
        Console.WriteLine("Nota 1.");
        a = int.Parse(Console.ReadLine());
        Console.WriteLine("Nota 2.");
        b = int.Parse(Console.ReadLine());
        Console.WriteLine("Nota 3.");
        c = int.Parse(Console.ReadLine());
        Console.WriteLine("Nota 4.");
        d = int.Parse(Console.ReadLine());
        Console.WriteLine("Nota 5.");
        e = int.Parse(Console.ReadLine());
        Console.WriteLine("Nota 6.");
        f = int.Parse(Console.ReadLine());
        Console.WriteLine("Nota 7.");
        g = int.Parse(Console.ReadLine());
        Console.WriteLine("Nota 8.");
        h = int.Parse(Console.ReadLine());
        Console.WriteLine("Nota 9.");
        i = int.Parse(Console.ReadLine());
        Console.WriteLine("Nota 10.");
        j = int.Parse(Console.ReadLine());
        soma=a+b+c+d+e+f+g+h+i+j;
        media=soma/10;
               if (media>=5) {
                      Console.WriteLine("Aluno {1} aprovado! Media {0}", media, nome);
               }
               else {
                      Console.WriteLine("Aluno {1} reprovado! Media {0}", media, nome);
               }
        Console.WriteLine("-----------------------------\n");
        }
    Console.ReadKey();
}
    
17.06.2017 / 01:59
0

Dude, quite directly and without input validations and code optimizations would look like this:

using System;

namespace StackOverflow
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            String nome;
            float LIM = 20;
            float soma = 0;
            float media;
            float mediaTurma;
            float a, b, c, d, e, f, g, h, i, j;
            int x, y;
            for (x = 0; x <= LIM; x++)
            {
                Console.WriteLine("Digite o nome do aluno:\t");
                nome = Console.ReadLine();
                Console.WriteLine("\nNota 1:");
                a = float.Parse(Console.ReadLine());
                Console.WriteLine("Nota 2:");
                b = float.Parse(Console.ReadLine());
                Console.WriteLine("Nota 3:");
                c = float.Parse(Console.ReadLine());
                Console.WriteLine("Nota 4:");
                d = float.Parse(Console.ReadLine());
                Console.WriteLine("Nota 5:");
                e = float.Parse(Console.ReadLine());
                Console.WriteLine("Nota 6:");
                f = float.Parse(Console.ReadLine());
                Console.WriteLine("Nota 7:");
                g = float.Parse(Console.ReadLine());
                Console.WriteLine("Nota 8:");
                h = float.Parse(Console.ReadLine());
                Console.WriteLine("Nota 9:");
                i = float.Parse(Console.ReadLine());
                Console.WriteLine("Nota 10:");
                j = float.Parse(Console.ReadLine());
                soma = a + b + c + d + e + f + g + h + i + j;
                media = soma / 10;
                if (media >= 5)
                {
                    Console.WriteLine(string.Format("Aluno aprovado! Media {0}\n", media));
                }
                else
                {
                    Console.WriteLine(string.Format("Aluno reprovado! Media {0}\n", media));
                }
                Console.WriteLine("-----------------------------\n\n");
            }
        }
    }
}

Tip, use 4 spaces in each line of the code to get formatted.

    
17.06.2017 / 02:00
0

I made a code using List

17.06.2017 / 04:58