04 11 과제

민우이·2022년 4월 12일
0

공부내용 정리

목록 보기
4/4

#include
using namespace std;
int main()
{//실습 1. 3 ~ 7 사이의 랜덤한 숫자를 출력하는 프로그램을 작성하자.

	srand(time(NULL));
	int randNumber;// 0 ~ 7
	randNumber = rand() % 5 + 3;
	//(randNumber <= 2) ? randNumber += 3 : randNumber;
	cout << randNumber << endl; // 1

	// 실습2  가장 작은 값과 큰 값을 입력 받아서, 그 사이의 임의의 값을 출력하는 프로그램을 작성하자.
	int max;
	int min;
	cout << "가장 작은 값 입력";
	cin >> min;
	cout << "가장 큰 값 입력";
	cin >> max;
	cout << rand() % (max - min + 1) + min << endl;

	//실습3.프로그램을 실행하면 내부적으로 1 ~9사이의 숫자가 정답으로 정해진다.유저가 1 ~9 사이의 숫자를 입력하면 맞으면 true, 틀리면 false

	int answer = rand() % 9 + 1;
	int input;
	cout << " 1~9 사이에 숫자 맞추기 " << endl;

	cin >> input;
	cout << boolalpha << (answer == input) << endl;
	//(answer == input) ? cout << "true" : cout << "false" << endl;

	//과제 rand 값의 데이터 타입은 ?  범위는 0 ~ 32767이다 4byte

// 교수님과 함께함@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 다음건

#include <iostream>
using namespace std;
int main()
{
	
	/*실습1. 3 ~7 사이의 랜덤한 숫자를 출력하는 프로그램을 작성하자.
		(3, 7 포함)

		실습2.가장 작은 값과 큰 값을 입력 받아서, 그 사이의 임의의 값을 출력하는 프로그램을 작성하자.

		실습3.프로그램을 실행하면 내부적으로 1 ~9 사이의 숫자가 정답으로 정해진다.유저가 1 ~9 사이의 숫자를 입력하면 맞으면 true, 틀리면 false*/
		int rand_num;
		// 입력 

		// 처리
		srand(time(NULL));
			//rand(); // 0 ~ 32767 % 5

		rand_num = 3 + rand() % 5;
		//3 + 0, 3 + 1, 3 + 2, 3 + 3, 3 + 4; //7-3 + 1
		// 출력 - 숫자 하나 출력

		cout << rand_num << endl;

		//실습 2. 
		//입력
		int input_min_number;
		int input_max_number;
		cout << "최소값을 입력하세요 : ";
		cin >> input_min_number;
		cout << "최대값을 입력하세요 : ";
		cin >> input_max_number;
		//처리
		rand_num = input_min_number + rand() % (input_max_number - input_min_number + 1);
														//7-3 + 1
		//출력
		 
		cout <<"실습2 " << rand_num << endl;

		//실습 3.
		//처리
		int correct_num = rand() % 9 + 1;
		cout <<"미리보는 정답" << correct_num << endl;
		
		//입력
		int input_quiz_number;
		cin >> input_quiz_number;

		
		//출력 : true or false
		(input_quiz_number == correct_num) ? cout << "true" << endl : cout << "false" << endl;
    
}

0개의 댓글

관련 채용 정보