Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

eXtremedlL

Como utilizar corretamente else // else if

Recommended Posts

Olá pessoal, bom dia!

 

Estou tentando fazer um programa onde preciso ler o nome e o salário (bruto) do funcionário e posteriormente informar ao mesmo qual será salário liquido (já descontando a % do INSS).  Porém, quando digito um salario acima de R$1501, quem tem um desconto de 11%, o sistema me retorna a resposta do desconto de 10%. Alguém poderia me dizer aonde estou errando? (Acredito que sintaxe para o else está incorreta).

 

//Exercicio 32 - Salario vs Desconto
#include <iostream>
using namespace std;
int main ( ) {
    float dp9, dp10, dp11, sb, scd, sl;
    char name[100];
    
    dp9 = 0.09;
    dp10 = 0.10;
    dp11 = 0.11;
    
    cout<<endl<<"CALCULE O SEU SALARIO (JA DESCONTADO O VALOR % DO INSS)"<<endl;
    
    cout<<endl<<"De R$0 a R$800 = 09%; de R$ 801 a 1500 = 10%; de 1501 ou mais = 11%"<<endl;
    
    cout<<endl<<"AVISO: NAO UTILIZE VIRGULA. USE SOMENTE PONTO FINAL."<<endl;
    cout<<"MAS SO USE PONTO PARA REPRESENTAR CENTAVOS. EX: 11111.11"<<endl;
    
    cout<<endl;
    
    system ("pause");
    
    cout<<endl<<"Digite o seu nome: ";
    cin>>name;
    
    cout<<endl<<"Informe o seu salario bruto: ";
    cin>>sb;
    
        if ( sb <= 800.99 ) {
            scd = sb * dp9;
            sl = sb - scd;
            cout<<endl<<"Solicitante: "<<name<<endl;
            cout<<endl<<"Salario liquido (-9% INSS) = R$"<<sl<<endl;
        }
        else if ( sb >= 801.00 || ( 801.00 == 1500.99 ) ) {
            scd = sb * dp10;
            sl = sb - scd;
            cout<<endl<<"Solicitante: "<<name<<endl;
            cout<<endl<<"Salario liquido (-10% INSS) = R$"<<sl<<endl;
        }
        else if ( sb >= 1501.0 ) {
            scd = sb * dp11;
            sl = sb - scd;
            cout<<endl<<"Solicitante: "<<name<<endl;
            cout<<endl<<"Salario liquido (-11% INSS) = R$"<<sl<<endl;
        }
    
    cout<<endl;
    
    system ("pause");
    
    return (0);
}

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

Galera, conseguir resolver o meu problema com a ajuda de um rapaz no facebook (que em parte estava no segundo e último else). Segue o novo código para os mesmos: 

 

        else if ( sb >= 801.00 && sb <= 1500 ) {
            scd = sb * dp10;
            sl = sb - scd;
            cout<<endl<<"Solicitante: "<<name<<endl;
            cout<<endl<<"Salario liquido (-10%% INSS) = R$"<<sl<<endl;
            }
        else {
            scd = sb * dp11;
            sl = sb - scd;
            cout<<endl<<"Solicitante: "<<name<<endl;
            cout<<endl<<"Salario liquido (-11%% INSS) = R$"<<sl<<endl;
            }

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

  • Conteúdo Similar

    • Por Rodrigo Bigas
      Olá colegas, 
      Desenvolvi um sistema simples de boletim escolar. Conforme os dados são inseridos nas textfields ao clicar no botão Resultado, deverá mostrar em uma JTable. O problema é que a última coluna (resultado) da JTable tem que estar dentro de uma condição if/else para setar se o aluno está "aprovado", "em recuperação" ou "reprovado conforme a condição". Estou com dificuldades em descobrir qual é o método correto que seta este resultado de forma dinâmica. Segue os prints:
       
      Conforme o código e o print acima, o sistema funciona somente para a primeira linha, porque está setando de forma estática, obtendo os valores do índice e coluna, qual seria o método para setar o valor de forma dinâmica do índice e coluna?
    • Por Sharank
      Strcat Function In C++
       
      I'm new to C and C++ programming, can anyone give me a hint on what I'm doing wrong here. I'm trying to write to concat function that takes to pointers to chars and concatenates the second to the first. The code does do that, but the problem is that it adds a bunch of junk at the end.
       
      For instance, when passing the arguments - "green" and "blue", the output will be "greenblue" plus a bunch of random characters. I also wrote the strlen function that strcat uses, which I will provide below it for reference. I'm using the online compiler at InterviewBit The exact instructions and specification is this:
       
      int main(int argc, char** argv)
      {
      const int MAX = 100;
       
      char s1[MAX];
      char s2[MAX];
       
      cout << "Enter your first string up to 99 characters. ";
      cin.getline(s1, sizeof(s1));
      int size_s1 = strlen(s1);
      cout << "Length of first string is " << size_s1 << "\n";
       
      cout << "Enter your second string up to 99 characters. ";
      cin.getline(s2, sizeof(s2));
      int size_s2 = strlen(s2);
      cout << "Length of second string is " << size_s2 << "\n";
      cout << " Now the first string will be concatenated with the second
      string ";
      char* a = strcat(s1,s2);
       
      for(int i = 0; i<MAX; i++)
      cout <<a;
       
      // system("pause");
      return 0;
      }
       
      //strcat function to contatenate two strings
      char* strcat(char *__s1, const char *__s2)
      {
      int indexOfs1 = strlen(__s1);
      int s2L = strlen(__s2);
      cout <<s2L << "\n";
      int indexOfs2 = 0;
      do{
      __s1[indexOfs1] = __s2[indexOfs2];
      indexOfs1++;
      indexOfs2++;
      }while(indexOfs2 < s2L);
       
       
      return __s1;
      }
       
      //Returns length of char array
      size_t strlen(const char *__s)
      {
      int count = 0;
      int i;
      for (i = 0; __s != '\0'; i++)
      count++;
      return (count) / sizeof(__s[0]);
       
      }
    • Por stefanyprs
      //modelo.html <!DOCTYPE html> <html lang="pt-br"> <head>     <meta charset="UTF-8">     <meta http-equiv="X-UA-Compatible" content="IE=edge">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <title>Hora do dia</title>     <link rel="stylesheet" href="estilo.css"> </head> <body onload="carregar()">     <header>         <h1> Hora do dia </h1>         </h1>     </header>     <section>         <div id="msg">             msg         </div>         <div id="foto">             <img class="imagem" src="fotomanha.jpg" alt="foto do dia">         </div>     </section>     <footer>         <p>&copy; Rodapé </p>     </footer>     <script src="script.js"></script> </body> </html>   //script.js function carregar () {     var msg = window.document.getElementById('msg')     var img  = window.document.getElementsByClassName('imagem')      var data = new Date()     var hora = data.getHours()          msg.innerHTML = 'Agora são ' + hora + ' horas'          if (hora >= 0 && hora < 12){         //Bom dia         img.src = 'fotomanha.jpg'         } else if (hora >= 12 && hora < 18){         //Boa tarde         img.src = 'fototarde.jpg'      } else {         //Boa noite         img.src = 'fotonoite.jpg'     } }   //estilo.css body{     background-color: aqua;     font: normal 15pt Arial; } header{     color:rgb(255, 255, 255);     text-align: center; } section{     background: white;     border-radius: 10px;     padding: 15px;     width: 500px;     margin:auto;     box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.329);      } footer{     color:white;     text-align: center;     font-style: italic;   } div{     text-align: center; } .imagem{     width: 500px;    /* largura da imagem */     height: 350px;   /*  altura da imagem  */     margin-top: 10px; /* margem do topo */ }
    • Por roberson abalaid
      #include <stdio.h>
      #include <stdlib.h>
      int arr[3][5];
      int main(){
          
          printf("Favor inserir os dados...\n");
          
          for(int i = 0; i < 3; i++){
              for(int j = 0; j < 5; j++){
                  scanf("%d", &arr[j]);
              }
          }
          
            printf("os valores inseridos foram...\n");
          
          for(int i = 0; i < 3; i++){
              for(int j = 0; j < 5; j++){
                  printf("  %d  ", arr[j]);
              }
              printf("\n");
          }
          return 0;
      }
    • Por biakelly
      Oi,
       
       não estou conseguindo fazer isso, podem me ajudar?
       
      <?php $botaoaluno = mysql_query("SELECT aluno FROM escola WHERE colegio_id='$colid'",$db); $alunoativo = mysql_num_rows($botaoaluno); if ($alunoativo = 1) { ?> <?php $pegaralunos = mysql_query("SELECT alunosdisponiveis FROM tabelasalunos WHERE userID='{$_SESSION['userid']}' and alunosID='{$objauALN["alunID"]}'", $db); $classe = mysql_num_rows($pegaralunos); if ($classe > 0) { ?> <button name="geraralunos">Aluno presente</button> <?php } else { ?> <button name="geraralunos">Aluno faltante</button> <? } } else{ ?> <p>Não tem aluno</p> <?php } ?> o que eu preciso, se o alunoativo for igual a 1, fazer o próximo IF, mas se ele for igual a 0 mostrar a mensagem (não tem aluno)
×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.