Please change the language of c

Asked 2 years ago, Updated 2 years ago, 30 views

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

int main(void)
{
    char str1[10];
    char str2[10];
    char str3[10];

    int num1, res;

    char *ps1 = str1;
    char *ps2 = str2;
    char *ps3 = str3;

    while (1)
    {
        printf("0P #1: ");
        scanf("%s", str1);
        if (ps1[0] == '0')
        {
            return 0;
        }
        printf("OPER: ");
        scanf("%s", str2);
        printf("OP #2: ");
        scanf("%s", str3);
        if (str2[0] == '@' && str2[1] == '\0')
        {
            strcat(str1, str3);
            num1 = atoi(str1);
            res = num1 + 1;
            printf("Result: %d\n", res);
        }
        else if (str2[0] == '#' && str2[1] == '\0')
        {
            strcat(str3, str1);
            num1 = atoi(str3);
            res = num1 - 1;
            printf("result : %d\n", res);
        }
        else
            return 0;
    }

    return 0;
}

I made the code according to the above question, but if there is anything wrong, please let me know and if you can make it well, please let me know

c

2022-09-22 18:29

1 Answers

#include <iostream>

using namespace std;


int main(void) {

    int OP1, OP2; // Incoming Variables 1, 2
    char OPER; // operator

    while (1) {

        cout << "0P #1: ";
        cin >> OP1;

        if (OP1 == 0) {

            break;
        }

        cout << endl << "OPER: ";
        cin >> OPER;

        cout << "OP #2: ";
        cin >> OP2;

        if (OPER == '@') {

           OP2 += 1;
            cout << OP1 << OP2 << endl;
        }

        else if (OPER == '#') {

           OP1 -= 1;
            cout << OP2 << OP1 << endl;
        }

        else {
            cout << "Wrong Operator!" << endl;
            main( );
        }
    }

    return 0;
}

I didn't know what you wanted, so I made it myself. If you want this, I wonder if you need to use Guji Strcat and atoi functions.


2022-09-22 18:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.