#include <stdio.h>
#include <stdlib.h>
//declaring functions
int rnl1(int, int);
int rnl2(int, int);
int rnl3(int, int);
int levels(int, int);
int main (){
int nOne = 1;
int nTen = 10;
int nHun = 100;
int nTh = 1000;
int ncompscore1 = levels(nOne, nTen);
int nuserscore1= levels(nOne, nTen);
int ncompscore2 = levels(nOne, nHun);
int nuserscore2= levels(nOne, nHun);
int ncompscore3 = levels(nOne, nTh);
int nuserscore3= levels(nOne, nTh);
return 0;
}//end main
//defining functions
int nTen = 10;
int nHun = 100;
int nTh = 1000;
int rnl1 (int nOne, int nTen){
return nOne + rand() % (nTen - nOne + 1);
}
int rnl2 (int nOne, int nHun){
return nOne + rand() % (nHun - nOne + 1);
}
int rnl3 (int nOne, int nTh){
return nOne + rand() % (nTh - nOne + 1);
}
int levels(int nOne, int nTh){
int norban1; //computers guess
int nszoboszlai1; //users input
int ncompscore1 = 1;
int wiw1;
int mrm1;
int nuserscore1=1;
int norban2; //computers guess
int nszoboszlai2; //users input
int ncompscore2 = 1;
int wiw2;
int mrm2;
int nuserscore2=1;
int norban3; //computers guess
int nszoboszlai3; //users input
int ncompscore3 = 1;
int wiw3;
int mrm3;
int nuserscore3=1;
//int tcs = ncompscore1 + ncompscore2 + ncompscore3;
//int tus = nuserscore1 + nuserscore2 + nuserscore3;
printf(" Enter your secret number: ");
scanf("%d", &nszoboszlai1);
norban1 = rnl1(nOne, nTen);//first number that the computer uses as a guess
while(norban1 != nszoboszlai1){
printf("\n Let's try for %d...", norban1);
if(norban1 > nszoboszlai1){
printf("\n The secret number the user chose is smaller than %d", norban1);
}
else{ //condition to set min
printf("\n The secret number the user chose is greater than %d", norban1);
}
ncompscore1++;
norban1 = rnl1(nOne, nTen);
}
printf("\n Let's try for %d...", norban1);
printf("\n Great success! The secret number is indeed %d\n", norban1);
printf("\n Aight, it's your turn you peasant. \n\n Make a guess: ");
scanf("%d", &wiw1);
mrm1 = rnl1(nOne, nTen);
while(wiw1 != mrm1){
if(wiw1 > mrm1){ //giving info to user
printf(" The secret number is smaller than %d", wiw1);
}
else{
printf(" The secret number is greater than %d", wiw1);
}
nuserscore1++; //increasing user score
printf("\n Try again champ: "); //letting user pick a new number after getting new information about the secret number
scanf("%d", &wiw1);
if(norban1 > nTen || norban1 < nOne){ //checking if value is in range
printf(" Value is not in defined range.\n Please enter it again: ");
scanf("%d", &wiw1);
}
}
printf("\n Great success! The secret number is indeed %d\n", wiw1);
printf("\n That's the end of level 1.") ;
printf("\n Computer's score: %d\n User's score: %d\n", ncompscore1, nuserscore1);
printf("\n Now onto level 2.");
printf(" Enter your secret number: ");
scanf("%d", &nszoboszlai2);
norban2 = rnl2(nOne, nHun);//first number that the computer uses as a guess
while(norban2 != nszoboszlai2){
printf("\n Let's try for %d...", norban2);
if(norban2 > nszoboszlai2){
printf("\n The secret number the user chose is smaller than %d", norban2);
}
else{ //condition to set min
printf("\n The secret number the user chose is greater than %d", norban2);
}
ncompscore2++;
norban2 = rnl2(nOne, nHun);
}
printf("\n Let's try for %d...", norban2);
printf("\n Great success! The secret number is indeed %d\n", norban2);
printf("\n Aight, it's your turn you peasant. \n\n Make a guess: ");
scanf("%d", &wiw2);
mrm2 = rnl2(nOne, nHun);
while(wiw2 != mrm2){
if(wiw2 > mrm2){ //giving info to user
printf(" The secret number is smaller than %d", wiw2);
}
else{
printf(" The secret number is greater than %d", wiw2);
}
nuserscore2++; //increasing user score
printf("\n Try again champ: "); //letting user pick a new number after getting new information about the secret number
scanf("%d", &wiw2);
if(norban2 > nHun || norban2 < nOne){ //checking if value is in range
printf(" Value is not in defined range.\n Please enter it again: ");
scanf("%d", &wiw2);
}
}
printf("\n Great success! The secret number is indeed %d\n", wiw2);
printf("\n That's the end of level 2.") ;
printf("\n Computer's score: %d\n User's score: %d\n", ncompscore2, nuserscore2);
printf("\n Now onto level 3.");
printf(" Enter your secret number: ");
scanf("%d", &nszoboszlai3);
norban3 = rnl3(nOne, nTh);//first number that the computer uses as a guess
while(norban3 != nszoboszlai3){
printf("\n Let's try for %d...", norban3);
if(norban3 > nszoboszlai3){
printf("\n The secret number the user chose is smaller than %d", norban3);
}
else{ //condition to set min
printf("\n The secret number the user chose is greater than %d", norban3);
}
ncompscore3++;
norban3 = rnl3(nOne, nTh);
}
printf("\n Let's try for %d...", norban3);
printf("\n Great success! The secret number is indeed %d\n", norban3);
printf("\n Aight, it's your turn you peasant. \n\n Make a guess: ");
scanf("%d", &wiw3);
mrm3 = rnl3(nOne, nTh);
while(wiw3 != mrm3){
if(wiw3 > mrm3){ //giving info to user
printf(" The secret number is smaller than %d", wiw3);
}
else{
printf(" The secret number is greater than %d", wiw3);
}
nuserscore3++; //increasing user score
printf("\n Try again champ: "); //letting user pick a new number after getting new information about the secret number
scanf("%d", &wiw3);
if(norban3 > nTh || norban3 < nOne){ //checking if value is in range
printf(" Value is not in defined range.\n Please enter it again: ");
scanf("%d", &wiw3);
}
}
printf("\n Great success! The secret number is indeed %d\n", wiw3);
printf("\n That's the end of level 3.") ;
printf("\n Computer's score: %d\n User's score: %d\n", ncompscore1, nuserscore1);
printf("\n Now onto level 2.");
printf("\n Total number of points for the computer is %d", ncompscore1+ncompscore2+ncompscore3);
printf("\n Total number of points for the user is %d", nuserscore1+nuserscore2+nuserscore3);
if((nuserscore1+nuserscore2+nuserscore3)>(ncompscore1+nuserscore2+ncompscore3)){
printf("\n LMAO you got outplayed by a machine, what a virgin\n");
}
else if((ncompscore1+nuserscore2+ncompscore3)>(nuserscore1+nuserscore2+nuserscore3)){
printf("\n You weren't smarter, you were luckier, pipe down. \n");
}
else {
printf("\n Can't even beat a computer, pussyo\n");
}
return ncompscore1, ncompscore2, ncompscore3, nuserscore1, nuserscore2, nuserscore3;
}