Jump to content
Fórum Script Brasil
  • 0

Quero deixar uma string minuscula


Question

Oi, estou fazendo uma calculadora e quando alguém quer multiplicar dois números, se ela digitar X quero q o X vire x para o programa entender. tentei fazer assim:

#include <iostream>
#include <ctype.h>

using namespace std;

string toLower (string string) {
    int i;

    for(i = 0; i < 3; i++)
        string = tolower(string[i]);
}

float operations (string operation, float num1, float num2) {
    if (operation == "+") {
        cout << num1 + num2;
    }

    else if (operation == "-") {
        cout << num1 - num2;
    }

    else if (operation == "/") {
        cout << num1 / num2, "\n";
    }

    else if (operation == "x") {
        cout << num1 * num2;
    }

    else {
        cout << "Enter a valid operation!!!";
        system("pause");
        exit(0);
    }
}

int main (){
    cout << "Enter a number: ";
    
    float n1 = 0;
    if (!(cin >> n1)) {
        cout << "Enter a valid value!!!\n";
        system("pause");
        exit(0);
    }
    
    cout << "Enter another number: ";
    
    float n2 = 0;
    if (!(cin >> n2)) {
        cout << "Enter a valid value!!!\n";
        system("pause");
        exit(0);
    }

    string operation_type = "None";
    
    cout << "[+ = Addition, - = Subtraction, X = Multiplication, / = Division]\n";
    
    cout << "Enter operation type: ";
    cin >> operation_type;
    toLower(operation_type);
    
    operations(operation_type, n1, n2);
    
}

 

Link to post
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      149408
    • Total Posts
      645900
×
×
  • Create New...