게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
[본삭금]c++ 어디가 문젠지 모르겠습니다
게시물ID : programmer_10941짧은주소 복사하기
작성자 : 와룡Ω
추천 : 0
조회수 : 287회
댓글수 : 2개
등록시간 : 2015/06/06 22:33:03
옵션
  • 본인삭제금지
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void baseball(int an, int x, int y, int z){
int st, ba;
st = 0;
ba = 0;
if ((an / 100) % (x * 100) == 0){
st += 1;
}
if ((an / 100) % (y * 100) == 0){
ba += 1;
}
if ((an / 100) % (z * 100) == 0){
ba += 1;
}
if (((an % 100) / 10) % (x * 10) == 0){
ba += 1;
}
if (((an % 100) / 10) % (y * 10) == 0){
st += 1;
}
if (((an % 100) / 10) % (z * 10) == 0){
ba += 1;
}
if (((an % 100) % 10) % x == 0){
ba += 1;
}
if (((an % 100) % 10) % y == 0){
ba += 1;
}
if (((an % 100) % 10) % z == 0){
st += 1;
}
cout << st << "STRIKE   " << ba << "BALL" << endl;
}
void main()
{
srand((unsigned int)time(NULL));// 인터넷 참고
int save1, save2, save3;
save1 = rand() % 9 + 1;
do{ save2 = rand() % 10; } while (save1 == save2);
do{ save3 = rand() % 10; } while (save1 == save3 || save2 == save3);
int ans;
ans = (100 * save1) + (10 * save2) + save3;

cout << ans<<endl; // 실험용 

cout << "베이스볼 게임을 시작합니다" << endl;
int game, game1,game2, game3;
game = 0;
int i;
for (i = 0; (i < 10) && (ans!=game); i++){
cout << "***********  "<<i+1<<"ROUND  **********" << endl;
cout << "숫자를 입력하세요" << endl;
do{ cin >> game; 
game1 = game / 100;
game2 = (game % 100) / 10;
game3 = (game % 100) % 10;
} while (game1==game2||game1==game3||game2==game3);
baseball(ans, game1, game2, game3);
}
cout << "###########  WIN  ################" << endl;
}

이제 한학기 배우고 제가 아는한도 내에서 야구게임을 만들어보는데 실행은 되는데 스트라이크랑 볼이 생각대로 작동하질 않습니다 ;;
랜덤숫자가 153이 나왔을때 플레이어가 152를 입력하면 2 스트라이크 0볼이 되야되는데 0스트라이크 0볼이 나옵니다
생각이 틀에 박혓는지 아무리 봐도 맞게 짠거 같이보여서 다른분들의 도움을 구해봅니다  
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호