通过电阻上的颜色计算电阻

时间:2019-03-19 20:17:23

标签: c electronics

#include<stdio.h>
#include<math.h>
#include<string.h>

int main(){

    int unos;
    char crna[20] = "crna";
    char braon[20] = "braon";
    char crvena[20] = "crvena";
    char narandzasta[20] ="narandzasta";
    char zuta[20] = "zuta";
    char zelena[20] = "zelena";
    char plava[20] = "plava";
    char ljubicasta[20] = "ljubicasta";
    char siva[20] = "siva";
    char bela[20] = "bela";
    char zlatna[20] = "zlatna";
    char srebrna[20] = "srebrna";

    puts("Unesite broj prstenova:");
    scanf("%i", &unos);

    if(unos == 5){

            int c1, c2, c3, m=0, t;
            char unos1[20] = "\0";
            int r;

            puts("Unesi boju 1. prstena:");
            scanf("%s",&unos1);

            if(strcmp(unos1, crna) == 0)
                c1 = 0;
            else if(strcmp(unos1, braon) == 0)
                c1 = 1;
            else if(strcmp(unos1, crvena) == 0)
                c1 = 2;
            else if(strcmp(unos1, narandzasta) == 0)
                c1 = 3;
            else if(strcmp(unos1, zuta) == 0)
                c1 = 4;
            else if(strcmp(unos1, zelena) == 0)
                c1 = 5;
            else if(strcmp(unos1, plava) == 0)
                c1 = 6;
            else if(strcmp(unos1, ljubicasta) == 0)
                c1 = 7;
            else if(strcmp(unos1, siva) == 0)
                c1 = 8;
            else if(strcmp(unos1, bela) == 0)
                c1 = 9;

            char unos2[20] = "\0";

            puts("Unesi boju 2. prstena:");
            scanf("%s", &unos2);

            if(strcmp(unos2, crna) == 0)
                c2 = 0;
            else if(strcmp(unos2, braon) == 0)
                c2 = 1;
            else if(strcmp(unos2, crvena) == 0)
                c2 = 2;
            else if(strcmp(unos2, narandzasta) == 0)
                c2 = 3;
            else if(strcmp(unos2, zuta) == 0)
                c2 = 4;
            else if(strcmp(unos2, zelena) == 0)
                c2 = 5;
            else if(strcmp(unos2, plava) == 0)
                c2 = 6;
            else if(strcmp(unos2, ljubicasta) == 0)
                c2 = 7;
            else if(strcmp(unos2, siva) == 0)
                c2 = 8;
            else if(strcmp(unos2, bela) == 0)
                c2 = 9;

            char unos3[20] = "\0";

            puts("Unesi boju 3. prstena:");
            scanf("%s", &unos3);

            if(strcmp(unos3, crna) == 0)
                c3 = 0;
            else if(strcmp(unos3, braon) == 0)
                c3 = 1;
            else if(strcmp(unos3, crvena) == 0)
                c3 = 2;
            else if(strcmp(unos3, narandzasta) == 0)
                c3 = 3;
            else if(strcmp(unos3, zuta) == 0)
                c3 = 4;
            else if(strcmp(unos3, zelena) == 0)
                c3 = 5;
            else if(strcmp(unos3, plava) == 0)
                c3 = 6;
            else if(strcmp(unos3, ljubicasta) == 0)
                c3 = 7;
            else if(strcmp(unos3, siva) == 0)
                c3 = 8;
            else if(strcmp(unos3, bela) == 0)
                c3 = 9;

            char mnoz[20] = "\0";
            puts("Unesi boju 4. prstena:");
            scanf("%s", &mnoz);

            if(strcmp(mnoz, crna) == 0)
                m = 1;
            else if(strcmp(mnoz, braon))
                m = 10;
            else if(strcmp(mnoz, crvena))
                m = 100;
            else if(strcmp(mnoz, narandzasta))
                m = 1000;
            else if(strcmp(mnoz, zuta))
                m = 10000;
            else if(strcmp(mnoz, zelena))
                m = 100000;
            else if(strcmp(mnoz, plava))
                m = 1000000;
            else if(strcmp(mnoz, ljubicasta))
                m = 10000000;
            else if(strcmp(mnoz, siva))
                m = 100000000;
            //else if(strcmp(mnoz, bela))
                //m = 10*10*10*10*10*10*10*10*10;
            else if(strcmp(mnoz, zlatna))
                m = 0.1;
            else if(strcmp(mnoz, srebrna))
                m = 0.01;

            r = ((c1*100)+(c2*10)+(c3*1)) * m;
            printf("%i,%i",m,r);

    }

    return 0;

}

一切正常,但是变量“ m”始终为10,如果在询问“ Unesi boju 4. prstena:”时输入“ narandzasta”,则应为1000。我可以将整数和字符的名称翻译为英文如果需要的话。我是编程的初学者(我们才刚刚开始学习字符串)。

1 个答案:

答案 0 :(得分:2)

您忘了与0进行比较以查看字符串是否相等:

'mute': async (msg) => {
    if(!msg.guild.member(msg.author).hasPermission('MUTE_MEMBERS')) { return msg.channel.send("Hmmm... I don't think you're allowed to use that. Missing permission: Mute Members.") }
    if(!msg.guild.member(bot.user).hasPermission('MANAGE_CHANNELS')) { return msg.channel.send("Uh oh, you have permission to use the command but it seems I do not. Missing permission: Manage channels.")}
    let embedError = new Discord.RichEmbed()
    .setColor("RED")
    .setTitle("Error")
    .setDescription("Correct format:\nAlexa mute [user eg: @YxriDev#0001] [time eg: 1h] [reason eg: Spamming.]")
    let args = msg.content.split(' ').slice(1).join(' ')
    let time = msg.content.split(' ').slice(3).join(' ')
    let reason = msg.content.split(' ').slice(4).join(' ')

    let muting = msg.mentions.users.first()
    if(!muting) { return msg.channel.send(embedError) }
    if(!time)  { return msg.channel.send(embedError) }
    if(!reason) { return msg.channel.send(embedError) }

      msg.guild.channels.forEach(x => {
        x.overwritePermissions(muting, {
          SEND_MESSAGES: false,
          VIEW_CHANNEL: null,
        })
      })
      msg.channel.send("Muted")
      console.log(time)

      setTimeout(function() {
        msg.guild.channels.forEach(x => {
          x.overwritePermissions(muting, {
            SEND_MESSAGES: true,
            VIEW_CHANNEL: null,
          })
        })
        msg.channel.send("unmuted")
    }, ms(time))

  }

然后将m声明为int,并在最终用途中将其声明为double,代码已更正:

 if(strcmp(mnoz, crna) == 0)
            m = 1;
        else if(strcmp(mnoz, braon) == 0)
            m = 10;
        else if(strcmp(mnoz, crvena) == 0)
            m = 100;
        else if(strcmp(mnoz, narandzasta) == 0)
            m = 1000;
        else if(strcmp(mnoz, zuta)==0)
            m = 10000;
        else if(strcmp(mnoz, zelena) == 0)
            m = 100000;
        else if(strcmp(mnoz, plava) == 0)
            m = 1000000;
        else if(strcmp(mnoz, ljubicasta) == 0)
            m = 10000000;
        else if(strcmp(mnoz, siva) == 0)
            m = 100000000;