lundi 9 novembre 2015

If-else statement trouble in Visual studio 2015

I'm a beginner in programming. I made a simple program in C# but it doesn't work properly. When I type "rezistenta" it should run the condition if (valoare=="rezistenta") When I type "capacitate" it should run the second if: if(valoare=="capacitate") In both cases the program runs the last else, it skips the first 2 if conditions.

The program:

#define _CRT_SECURE_NO_WARNINGS  //directive preprocesor
#include<stdio.h>
#include<conio.h>


void main(void)
{
    char valoare[100];
    float C1, C2, CS, CP;
    float R1, R2, Rs, Rp;


    printf("\nCapacitate sau Rezistenta? ");
    scanf("%s", &valoare);
    printf("\nAti introdus= %s", valoare);

    if (valoare == "rezistenta")

    {   printf("\nIntroduceti valorile rezistentelor: ");
        scanf("%f%f", &R1, &R2);
        Rs = R1 + R2;
        printf("\nRezistenta echivalenta serie este: *%6.3f*", Rs);
        Rp = (R1*R2) / (R1 + R2);
        printf("\nRezistenta echivalenta paralel: *%6.3f*", Rp);
    }//end if

    else
        if (valoare == "capacitate")

        {
            printf("\nIntroduceti valorile capacitatilor: ");
            scanf("%f%f", &C1, &C2);
            CS = (C1*C2) / (C1 + C2);
            printf("\nValoarea capacitatilor serie este = *%-6.4f*", CS);
            CP = C1 + C2;
            printf("\nValoarea capacitatilor in paralel este= *%-6.4f*", CP);


        }
        else
            printf("\nSunteti nehotarat vi le dau pe amandoua");



    printf("\nIntroduceti valorile rezistentelor: ");
    scanf("%f%f", &R1, &R2);
    Rs = R1 + R2;
    printf("\nRezistenta echivalenta serie este: *%6.3f*", Rs);
    Rp = (R1*R2) / (R1 + R2);
    printf("\nRezistenta echivalenta paralel: *%6.3f*", Rp);

    printf("\nIntroduceti valorile capacitatilor: ");
    scanf("%f%f", &C1, &C2);
    CS = (C1*C2) / (C1 + C2);
    printf("\nValoarea capacitatilor serie este = *%-6.4f*", CS);
    CP = C1 + C2;
    printf("\nValoarea capacitatilor in paralel este= *%-6.4f*", CP);



    _getch();



}//end main

Aucun commentaire:

Enregistrer un commentaire