조건문

장승현·2023년 11월 13일

C++

목록 보기
1/3
post-thumbnail
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>

/*int cp100(int a) { 
    
    if (a < 100) {
        std::cout << "참값 a가 100보다 작군요" << std::endl;
        std::cout << "조건문이 참일 때 2개 이상 실행문 작성 가능!!!" << std::endl;
    }
    else {
        std::cout << "거짓값!! 100보다 커요!!!!" << std::endl;
        std::cout << "조건문이 거짓일 때도 2개 이상 실행문 작성 가능!!!" << std::endl;
    }

    std::cout << "비교 끝" << std::endl;
    return 0;
}

int main() {
    int a;
    
    a = 100;
    cp100(a);
    a = 90;
    cp100(a);
    
    return 0;
}*/

//###############################################################################

/*int oddeven(int num) {
    if (num % 2 == 0) {
        std::cout << "짝수입니다" << std::endl;
    }
    else {
        std::cout << "홀수입니다" << std::endl;
    }

    std::cout << "끝!!" << std::endl;
    return 0;
}

int main() {
    int a;

    std::cout << "숫자를 입력해주세요: ";
    std::cin >> a;
    std::cout << a << std::endl;

    oddeven(a);
    return 0;
}*/

//###############################################################################

/*int main() {
    int a;

    std::cout << "숫자를 입력해주세요: ";
    std::cin >> a;
    std::cout << a << std::endl;

    if (a < 50) {
        std::cout << "down" << std::endl;
    }
    else if (a > 50) {
        std::cout << "up" << std::endl;
    }
    else {
        std::cout << "it's 50" << std::endl;
    }
    
    return 0;
}*/

//###############################################################################

/*int clacGrade(int score) {
    if (90 <= score and score <= 100) {
        std::cout << "A" << std::endl;
    }
    else if (80 <= score) {
        std::cout << "B" << std::endl;
    }
    else if (70 <= score) {
        std::cout << "C" << std::endl;
    }
    else if (60 <= score) {
        std::cout << "D" << std::endl;
    }
    else if (score < 60) {
        std::cout << "F" << std::endl;
    }
    else {
        std::cout << "not correct score" << std::endl;
    }
    return 0;
}

int main() {
    int score;

    std::cout << "점수를 입력해주세요: ";
    std::cin >> score;
    std::cout << score << std::endl;

    clacGrade(score);
    return 0;
}*/

//###############################################################################

/*int main() {
    std::string nums;
    int nums_array[3];
    char separator = ',';
    
    std::cout << "숫자 3개를 입력해주세요(구분자 ,): ";
    std::cin >> nums;
    std::cout << nums << std::endl;

    std::istringstream iss(nums);
    std::string str_buf;
    int i = 0;
    while (getline(iss, str_buf, separator)) {
        nums_array[i] = std::stoi(str_buf);
        i += 1;
    }
    std::cout << *std::max_element(nums_array, nums_array + 3);
    
    return 0;
}*/

//###############################################################################

/*int main() {
    int num1, num2;
    std::string op;

    std::cout << "첫번째 숫자를 입력하세요 : ";
    std::cin >> num1;
    std::cout << num1 << std::endl;
    std::cout << "연산자를 입력하세요(+,-,*,/) : ";
    std::cin >> op;
    std::cout << op << std::endl;
    std::cout << "두번째 숫자를 입력하세요 : ";
    std::cin >> num2;
    std::cout << num2 << std::endl;

    if (op == "+") {
        std::cout << num1 << " + " << num2 << " = " << num1 + num2 << std::endl;
    }
    else if (op == "-") {
        std::cout << num1 << " - " << num2 << " = " << num1 - num2 << std::endl;
    }
    else if (op == "*") {
        std::cout << num1 << " * " << num2 << " = " << num1 * num2 << std::endl;
    }
    else if (op == "/") {
        std::cout << num1 << " / " << num2 << " = " << num1 / num2 << std::endl;
    }
    else {
        std::cout << "연산자가 틀렸습니다." << std::endl;
    }
    
    return 0;
}*/

//###############################################################################

/*int main() {
    std::string scores;
    int score_array[4], score_sum = 0;
    char separator = ',';
    
    std::cout << "4과목의 점수를 입력해주세요(구분자 ,): ";
    std::cin >> scores;
    std::cout << scores << std::endl;

    std::istringstream iss(scores);
    std::string str_buf;
    int i = 0;
    int right = 1;
    while (getline(iss, str_buf, separator)) {
        if (std::stoi(str_buf) > 100 or std::stoi(str_buf) < 0) {
            std::cout << "잘못된 점수 입력입니다." << std::endl;
            right = 0;
            break;
        }
        
        score_array[i] = std::stoi(str_buf);;
        score_sum += std::stoi(str_buf);
        i += 1;
    }

    if (right == 1) {
        if (*std::min_element(score_array, score_array+4) < 40) {
            std::cout << "40점 미만 과목으로 인해 과락하셨습니다." << std::endl;
        }
        else if ((score_sum / 4) >= 60) {
            std::cout << "평균 점수 60점 이상으로 합격하셨습니다." << std::endl;
        }
        else if ((score_sum / 4) < 60) {
            std::cout << "평균 점수 60점 미만으로 불합격하셨습니다." << std::endl;
        }   
    }
    
    return 0;
}*/
profile
늦더라도 끝이 강한 내가 되자

0개의 댓글