Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

operations variables

Discussion in '2D' started by Damascoy, Mar 24, 2020.

  1. Damascoy

    Damascoy

    Joined:
    Sep 29, 2019
    Posts:
    2
    Can someone help me with these variable operations? I don't know what's going wrong

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Scriptzinho : MonoBehaviour
    {
    private object print;

    // Start is called before the first frame update
    void Start()
    {
    switch (op)
    {
    char op;
    int result, a, b;
    print("Digite um inteiro:");
    scanf("%d", &a);
    print("Digite outro inteiro:");
    scanf("%d", &
    print("Selecione a operação:");
    scanf("%*c%c", &op);

    switch (op)
    {
    case '+':
    result = a + b;
    break;
    case '*':
    result = a * b;
    break;
    case '-':
    result = a - b;
    case '/':
    result = a / b;
    default:
    break;
    }
    print("Resultado:%d\n", result);
    scanf("%*c%*c");
    return 0;
    }

    }

    // Update is called once per frame
    void Update()
    {

    }
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Hi

    @ProfCreeper

    Help with what?

    "I don't know what's going wrong"

    What should be happening - can you explain? And what doesn't work in current code - i.e - what is your question actually?

    And could you please format your code with code tags, you can edit your post and change the code part so it is readable.
     
  3. Damascoy

    Damascoy

    Joined:
    Sep 29, 2019
    Posts:
    2
    my teacher asked to make a program that receives two numbers and performs the operations
    but I don't know how to do it, so I made this code, but I don't know if it's right, I changed the code, but it's still giving an error

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Scriptzinho : MonoBehaviour
    {

    // Start is called before the first frame update
    void Start()
    {
    switch (op)
    {
    default:
    break;
    }
    char op;
    int result, a, b;
    print("Digite um inteiro:");
    scanf("%d", &a);
    print("Digite outro inteiro:");
    scanf("%d", &
    print("Selecione a operação:"));
    scanf("%*c%c", &op);

    switch (op)
    {
    case '+':
    result = a + b;
    break;
    case '*':
    result = a * b;
    break;
    case '-':
    result = a - b;
    case '/':
    result = a / b;
    default:
    break;
    }
    print("Resultado:%d\n", result);
    scanf("%*c%*c");
    return 0;
    }
    }


    // Update is called once per frame
    void Update()
    {

    }

    @eses