I can't find the mistake on the do-while. The loop keeps going if I answer 'N' to the question.(The app is for finding the average of height of an uncertain number of people).
#include <stdio.h>
#include <stdlib.h>
/*
*
*/
int main(int argc, char** argv) {
int i;
float measure[i],sum,average;
char sex;
char yn;
do{
for(i=1;i;i++) {
printf("Persoa %d",i);
printf("\nIndique se é home (H) ou muller (M): ");
scanf("%s",&sex);
while((sex != 'M') && (sex != 'H'))
{
printf("Lo ha escrito mal.");
printf("\nIndique se é home (H) ou muller (M): ");
scanf("%s",&sex);
}
printf("Indique a súa measure (en metros): ");
scanf("%f",&measure[i]);
sum=sum+measure[i];
printf("\nDesea seguir? (Y/N): ");
scanf("%s",&yn);
while((yn != 'Y') && (yn != 'N'))
{
printf("Lo ha escrito mal.");
printf("\nDesea seguir? (Y/N): ");
scanf("%s",&yn);
}
}
}while(yn == 'Y');
average=sum/i;
printf("\nA media de measures é: %f m.",average);
return (EXIT_SUCCESS);
Need help guys. I need to send this to my teacher tomorrow. I'm a noob on this language :(
two main errors are:
the most critical is:
float measure[i];
you have to declare exactly the size of the table eg:
float measure[50];
the second is: scanf string format for char is "%c" not "%s"
still other error exists.
try this correction to your program
#include <stdio.h>
#include <stdlib.h>
/*
*
*/
#define NB_MESURES 50
int main(int argc, char** argv) {
int i=0;
float measure[NB_MESURES] /* NB_MESURES is predefined to be 50*/
,sum=0,average=0;
char sex=0;
char yn=0;
while(1){ /*endless loop (1)*/
printf("Persoa %d",i);
printf("\nIndique se é home (H) ou muller (M): ");
while(1) /*endless loop (level 2)*/
{
scanf(" %c",&sex);
if((sex == 'M') || (sex == 'H')) break; /*Upper case*/
if((sex == 'm') || (sex == 'h')) break; /*Lower case*/
/* ok exit loop (level 2)
else show the help message */
printf("Lo ha escrito mal.");
printf("\nIndique se é home (H) ou muller (M): ");
}
printf("Indique a súa measure (en metros): ");
scanf("%f",&measure[i]);
sum=sum+measure[i];
i++;
if(i==NB_MESURES){
/*
we can not add more than 50 elements
exiting loop (1)
*/
printf("\nMax Allowed entries is %d\n",NB_MESURES);
break;
}else{
printf("\nDesea seguir? (Y/N): ");
while(1) /* loop (level 2) */
{
scanf(" %c",&yn);
if((yn == 'Y') || (yn == 'N')) break;
if((yn == 'y') || (yn == 'n')) break;
/* if the input was different than ['Y','y','N','n']
show newt message else we break and use yn in the next check to exit loop (level 1)
*/
printf("Lo ha escrito mal.");
printf("\nDesea seguir? (Y/N): ");
}
if((yn == 'N') || (yn == 'n')) break; /*Exit level 1*/
}
}
average=sum/i;
printf("\nA media de measures é: %f m.\n",average);
return (EXIT_SUCCESS);
}
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am making a tic tac toe game in C language but it won't run
I don't know where is the error at. The compiler just freeze without any error messages this is my code below if anyone could point out the errors and the way of writing clean code i am a new programmer who is still learning and this is my first project.
#include <stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>
void BuildGround;
void first_player_choice;
void second_player_choice;
void ai_choice;
char result;
void AiVsP;
void PVP;
int count_ground;
int main()
{
char ground[9] = {' ',' ',' ',' ',' ',' ',' ',' ',' '};
int mode;
printf("choose game mode (1 or 2): ");
printf("1. PVP ");
printf("2. AI vs P: ");
scanf("%d",&mode);
switch(mode){
case 1 :
PVP();
break;
case 2:
AiVsP();
break;
default:
printf("Invalid input: ");
break;
}
}
int count_ground(char symbole){
int total=0;
for(int i =0 ; i<9 ; i++){
if(ground[i]== symbole)
total=+ 1;
}
}
void AiVsP(void){
char name[100];
printf("Enter your name : ");
gets(name);
while(1==1){
system("cls");
BuildGround();
if (count_ground('X') == count_ground('O')){
puts("Turn: ");
puts(name);
fisrt_player_choice();
}
else{
ai_choice;
}
char winner == result();
if (winner == 'X'){
system("cls");
BuildGround();
puts("The winner is: ");
puts(name);
break;
}
else if
(winner == 'O'){
system("cls");
BuildGround();
printf("AI wins ")
break;
}
else winner == 'D'
printf("The Game is Draw ")
break;
}
}
void PVP(void){
char name1[100];
char name2[100];
printf("Enter the name of the first player : ");
gets(name1);
printf("Enter the name of the second player : ");
gets(name2);
while(1==1){
system("cls");
BuildGround;
if (count_ground('X') == count_ground('O')){
puts("Turn: ");
puts(name1);
first_player_choice();
}
else{
puts("Turn: ");
puts(name2);
second_player_choice();
}
char winner == result();
if (winner == 'X'){
system("cls");
BuildGround();
puts("The winner is: ");
puts(name1);
break;
}
else if
(winner == 'O'){
system("cls");
BuildGround();
puts("The winner is: ");
puts(name2);
break;
}
else winner == 'D'
printf("The Game is Draw ")
break;
}
}
char result(char ground[9]){
int i;
for(i = 0;i<=6; i+=3)//it's for row
if(ground[i] == ground[i+1]== && ground[i+1]== ground[i+2]&& ground[i] != ' ' ){
return ground[0];
}
for(i = 0;i<3; i++)//it's for column
if(ground[i]== ground[i+3]== && ground[i+3]== ground[i+6] && ground[i]!=' ' ){
return ground[1];
}
if(ground[0] == && ground[4] == && ground[4]== ground[8] && ground[0]!=' '){
return ground[4];
}
else if(ground[2] == && ground[4] == && ground[4]== ground[6] && ground[2]!=' '){
return ground[6];
}
else if(count_ground('X')+ count_ground('O') < 9){
return 'C';
}else return 'D';
}
void ai_choice(void){
srand(time(0));
do{
int c;
c = rand()%10;
}
while(ground[c]!= ' ');
ground(c)='O';
}
void first_player_choice(char ground[9]){
while(1==1){
int position;
printf("Choose your position from 0-8 (column wise): ");
scanf("%d", &position);
if(position < 0 || position > 8 ){
printf("Invalid number please try again: ");
}
else if(ground[position]!=' '){
printf("Position is already taken please try again: ");
}
else
ground[c]='X';
break;
}
}
void second_player_choice(char ground[9]){
while(1==1){
int position;
printf("Choose your position from 0-8 (column wise): ");
scanf("%d", &position);
if(position < 0 || position > 8 ){
printf("Invalid number please try again: ");
}
else if(ground[position]!=' '){
printf("Position is already taken please try again: ");
}
else
ground[c]='O';
break;
}
}
void BuildGround(char ground[9]){
printf("\t\t\t\tT i c t a c t o e");
printf("\nPlayers 1 Symbol: X");
printf("\nPlayers 2 Symbol: O");
printf("\n\t\t\t | | ");
printf("\n\t\t\t %c | %c | %c ",ground[0],ground[1],ground[2]);
printf("\n\t\t\t_______|_______|_______");
printf("\n\t\t\t %c | %c | %c ",ground[3],ground[4],ground[5]);
printf("\n\t\t\t_______|_______|_______");
printf("\n\t\t\t %c | %c | %c ",ground[6],ground[7],ground[8]);
printf("\n\t\t\t | | ");
}
You have multiple issues, like
case 1 :
PVP; //this is not a function call.
break;
should use the call like
PVP();
or rather, pvp(); , as uppercase letters usually carry special meaning, not a good idea to use them for user-defined code.
That said, function definitions like
void ai_choice{
srand(time(0));
and
void PVP{
char name1[100];
char name2[100];
are wrong syntax, you have to use the parenthesis, like
void PVP (void){
char name1[100];
char name2[100];
That said, scanf("%d",& mode); is usually written as scanf("%d",&mode); (no space between operand and operator, but that's just a choice).
i tried to make a calculator but could the compiler is checking my if conditions properly.
here is my code,
i could not figure out how to solve this
#include <stdio.h>
#include <stdlib.h>
int main()
{
int first;
int sec;
char mode;
printf("enter your forst number : ");
scanf("%d",&first);
printf("enter your second number : ");
scanf("%d",&sec);
printf("to add press \"a\" \n");
printf("to subtract press \"s\" \n");
printf("to multiply press \"m\" \n");
printf("to divide press \"d\" \n");
printf("so, what do you wanna do ");
scanf(" %c",&mode);
printf("%d %d %s \n",first,sec,mode);
if (mode == 'a')
{
printf("%d \n",first + sec);
}
else if (mode == "s")
{
printf("%d \n",first-sec);
}
else if (mode == "m")
{
printf("%d \n",first*sec);
}
else if (mode == "d")
{
printf("%d \n",first/sec);
}
else
{
printf("enter a valid operation code \n");
}
return 0;
}
void def(char name[],int age)
{
printf("het ur a %s and yo age is %i \n",name,age);
}
first attempt tried using a string instead of character (failed )
second attempt tried using a character but failed though!!
For comparing a single character in c, you must use single quotes. Consider an array of characters array[4] = {'c','a','r','\0'};
if(array[0] == 'c'){
//...
}
Comparing with double quotes, make the value inside it a string. For comparing strings you should #include <strings.h> and use the strcmp function.
There are two problems
mode == "s" mode is a char so just use mode == 's' and do the same for others also.
printf("%d %d %s \n",first,sec,mode); should be printf("%d %d %c \n",first,sec,mode);
you are using %s for printing a char
In your code "s" is a string not a caracter,to get a caracter you should write like this: 's'
here is the correction of your code :
int main()
{
int first;
int sec;
char mode;
printf("enter your forst number : ");
scanf("%d",&first);
printf("enter your second number : ");
scanf("%d",&sec);
printf("\nMenu : \n");
printf("\nto add press \"a\" \n");
printf("to subtract press \"s\" \n");
printf("to multiply press \"m\" \n");
printf("to divide press \"d\" \n");
printf("so, what do you wanna do ");
scanf(" %c", &mode);
printf("%d %d %c \n",first,sec,mode);
if(mode == 'a')
{
printf("%d \n",first + sec);
}
else if (mode == 's')
{
printf("%d \n",first-sec);
}
else if (mode == 'm')
{
printf("%d \n",first*sec);
}
else if (mode == 'd')
{
printf("%d \n",first/sec);
}
else
{
printf("enter a valid operation code \n");
}
return 0;
}
I don't know where is my mistake, please I need your help. When I enter a wrong data in my username and password and it will ask if YES or NO to try again. If I type Y as a YES I can't type in username anymore.
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main() {
printf ("\n\t\t Welcome To Your Payroll Account!");
printf ("\n\t\t Please Enter Your Username & Password To Proceed.");
printf ("\n\t ********************************************************* \n \n \n");
char password [10], username [10], ch;
char name [10] = "username";
char pass[10] = "password";
char month, ename, address;
float regpay,regov,RD,RDOT,meal;
float SSS,PH,PI,Union,other,SSSsal,Loan,Hloan,ULoan,ELoan,TD;
float TE,Netpay;
int n,day,year,i;
char input;
char again = 'Y';
while (again == 'Y' || again =='y') {
printf("Username: ");
gets (username);
printf("Password: ");
for (i = 0; i<8; i++){
ch = getch();
password[i] = ch;
printf ("*");
}
password[i] = 0;
printf("\n Your password is: ");
for (i =0; i<8; i++) {
printf("%c", password[i]);
}
if(strcmp(pass,password) == 0 && strcmp(name,username) == 0) {
printf("\n \n You are logged in! \n");
printf("Enter # to proceed \n");
scanf("%c", &input);
} else {
printf("\n \n Incorrect username or password");
printf("\n\n Do you want to try again? YES(Y) / NO(N) \n");
printf("Continue? ");
scanf("%c", &again);
again;
if (again == 'N' || again == 'n') {
system ("pause");
return 0;
} else {
again;
}
}
}
system ("pause");
return 0;
}
printf("Continue? ");
scanf("%c", &again);
again;
if (again == 'N' || again == 'n') {
system ("pause");
return 0;
} else {
again;
}
Here while taking char input you are using scanf()
so will give character input plus enter.
again will get the input character, but enter will remains in buffer.
When while loop iterates, gets which is waiting for username input will get enter character automatically from the buffer, so the username input will be skipped.
solution is to add getch() after
scanf("%c", &again);
Hope this will hep you.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am also having the "undefined reference to ERPSGame()" error as well as the "Id returned 1 exit status". Did I declare something wrong? I am using Orwell Dev C++.
What seems to be the problem? Is it my compiler ?
Check out the whole code:
/* GameBox BETA v0.2 */
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
void ERPS();
void Menu();
void BJack();
void Log();
int ERPSGame();
void ERPSInstruct();
int main() {
char Choice;
system("cls");
printf("\t\t Welcome to Mark and Leroy's GameBox BETA v0.2 \n\n\n");
printf("--------------------------------------------------------------------------------\n");
printf("\t _________________________________________________________\n");
printf("\t ||_____________________________________________________|| \n");
printf("\t || \t\t|| \n");
printf("\t || \t\t|| \n");
printf("\t || \t\t|| \n");
printf("\t ||\t Please press 'A' to continue to the menu\t||\n");
printf("\t ||\t \t||\n");
printf("\t ||\t Otherwise, press 'F' to exit the program\t||\n");
printf("\t ||_____________________________________________________|| \n");
printf("\t ||_____________________________________________________||\n");
printf("--------------------------------------------------------------------------------\n\n");
/* Drawing Starts Here */
printf("\t\t ========================================\n");
printf("\t\t || || \n");
printf("\t\t || ||=============== || \n");
printf("\t\t || || || \n");
printf("\t\t || || ======= || \n");
printf("\t\t || || Gamebox || || \n");
printf("\t\t || || BETA v0.2 || || \n");
printf("\t\t || ||==============|| || \n");
printf("\t\t || || \n");
printf("\t\t || ||==== ||====|| == == || \n");
printf("\t\t || || || || || == == || \n");
printf("\t\t || ||===|| || || == || \n");
printf("\t\t || ||___|| ||====|| == == || \n");
printf("\t\t || == == || \n");
printf("\t\t || Artwork by: Mark Sanchez || \n");
printf("\t\t ========================================\n");
/* Drawing Ends Here */
scanf("%c", &Choice);
switch (Choice) {
case'A':case'a':{
Menu();
break;
}
case'F':case'f':{
exit(0);
}
default: {
main();
}
}
return 0;
}
void Menu() {
char Choice1;
system("cls");
printf("\t\t Welcome to Mark and Leroy's GameBox BETA v0.2 \n\n\n");
printf("--------------------------------------------------------------------------------\n\n");
printf("\t\t Press 'R' to play the Enhanced Rock-Paper-Scissors game\n\n\n");
printf("\t\t Press 'B'to play Blackjack\n\n\n");
printf("\t\t Press 'C' to view the changelog\n\n\n");
printf("--------------------------------------------------------------------------------\n\n");
scanf("%c", &Choice1);
switch(Choice1) {
case'R':case'r': {
ERPS();
break;
}
case'B':case'b': {
BJack();
break;
}
case'C':case'c': {
Log();
break;
}
default: {
Menu();
}
}
}
void ERPS() {
system("cls");
char Instruct1;
char Instruct2;
/* Menu of ERPS */
printf("\t\t\t Welcome to ENHANCED Rock Paper Scissors\n\n\n");
printf("\t\t\t Press A to start the game\n\n");
printf("\t\t\t Press S to view the instructions\n\n");
printf("\t\t\t Press 'P' to return to the main menu\n");
scanf("%c", &Instruct1);
scanf("%c", &Instruct2);
switch(Instruct2) {
case'A':case'a': {
ERPSGame();
break;
}
case'S':case's': {
ERPSInstruct();
break;
}
case'P':case'p': {
Menu();
break;
}
default:{
ERPS();
}
}
}
int rand_i(int n)
{
int rand_max = RAND_MAX - (RAND_MAX % n);
int ret;
while ((ret = rand()) >= rand_max);
return ret/(rand_max / n);
}
int weighed_rand(int *tbl, int len)
{
int i, sum, r;
for (i = 0, sum = 0; i < len; sum += tbl[i++]);
if (!sum) return rand_i(len);
r = rand_i(sum) + 1;
for (i = 0; i < len && (r -= tbl[i]) > 0; i++);
return i;
}
int ERPSGame(int argc, const char *argv[]) /* THIS IS THE ERPSGame */
{
char umove[10], cmove[10], line[255];
int user, comp;
int tbl[]={0,0,0};
int tbllen=3;
printf("Hello, Welcome to rock-paper-scissors\nBy The Elite Noob\n");
mainloop:
while(1)
{ // infinite loop :)
printf("\n\nPlease type in 1 for Rock, 2 For Paper, 3 for Scissors, 4 to quit\n");
srand(time(NULL));
comp = (weighed_rand(tbl, tbllen) + 1) % 3;
fgets(line, sizeof(line), stdin);
while(sscanf(line, "%d", &user) != 1) //1 match of defined specifier on input line
{
printf("You have not entered an integer.\n");
fgets(line, sizeof(line), stdin);
}
if( (user > 4) || (user < 1) )
{
printf("Please enter a valid number!\n");
continue;
}
switch (comp)
{
case 1 :
strcpy(cmove, "Rock");
break;
case 2 :
strcpy(cmove, "Paper");
break;
case 3 :
strcpy(cmove, "Scissors");
break;
default :
printf("Computer Error, set comp=1\n");
comp=1;
strcpy(cmove, "Rock");
break;
}
switch (user)
{
case 1 :
strcpy(umove, "Rock");
break;
case 2 :
strcpy(umove, "Paper");
break;
case 3 :
strcpy(umove, "Scissors");
break;
case 4 :
printf("Goodbye! Thanks for playing!\n");
return 0;
default :
printf("Error, user number not between 1-4 exiting...");
goto mainloop;
}
if( (user+1)%3 == comp )
{
printf("Comp Played: %s\nYou Played: %s\nSorry, You Lost!\n", cmove, umove);
}
else if(comp == user)
{
printf("Comp Played: %s\nYou Played: %s\nYou Tied :p\n", cmove, umove);
}
else
{
printf("Comp Played: %s\nYou Played: %s\nYay, You Won!\n", cmove, umove);
}
tbl[user-1]++;
}
}
void ERPSInstruct() {
system("cls");
char Instruct3;
printf("\t\t\t Instructions of the Game \n\n");
printf("\t\t\t There will be 5 choices to choose from\n");
printf("\t\t\t 1. Rock\n");
printf("\t\t\t 2. Paper\n");
printf("\t\t\t 3. Scissors\n");
printf("\t\t\t 4. Lizard\n");
printf("\t\t\t 5. Spock\n\n\n\n");
printf("\t\t This is the mechanism of the choices: \n\n");
printf("\t\t Scissor cuts paper. \n\n");
printf("\t\t Paper covers rock. \n\n");
printf("\t\t Rock crushes lizard. \n\n");
printf("\t\t Lizard poisons spock. \n\n");
printf("\t\t Spock smashes scissors. \n\n");
printf("\t\t Scissors decapitate lizard. \n\n");
printf("\t\t Lizard eats paper. \n\n");
printf("\t\t Paper disproves spock. \n\n");
printf("\t\t Spock vaporizes rock. \n\n");
printf("\t\t Rock crushes scissors. \n\n");
printf("\t\t\t Press 'P' to return to the menu\n");
scanf("%c", &Instruct3);
switch(Instruct3) {
case'P':case'p': {
Menu();
break;
}
default: {
ERPSInstruct();
}
}
}
void BJack() {
system("cls");
char Instruct2;
printf("BLACKJack \n\n\n");
printf("\t\t\t Press 'P' to return to the menu\n");
scanf("%c", &Instruct2);
switch(Instruct2) {
case'P':case'p': {
Menu();
break;
}
default: {
BJack();
break;
}
}
getch();
}
void Log() {
system("cls");
char Instruct3;
printf("CHANGELOG: \n\n\n");
printf(" 0.1 -- Fixed a bug wherein the program forces\n to do 'default' upon choosing a game\n\n\n");
printf("-----------------------------------------------\n\n");
printf(" 0.2 -- Fixed display in CMD: Added a few dividers \nas well as correcting a few grammatical mistakes\n");
printf(" Added awesome graphics \n\n\n");
printf("-----------------------------------------------\n\n");
printf("\t\t\t Press 'P' to return to the menu\n");
scanf("%c", &Instruct3);
switch(Instruct3) {
case'P':case'p': {
Menu();
break;
}
default: {
Log();
break;
}
}
}
Is it my way of declaring ERPSGame? I used int.
Function declaration is not matched with function definition.
Declaration:
int ERPSGame();
Definition
int ERPSGame(int argc, const char *argv[])
In Dev-C++, under Tools -> Compiler Options, put "-Wall" in the "...commands when calling compiler" box. It will be helpful for you to get warnings and do effective coding and saves your time too.
When you take in instruct1 and then use instruct2 in the switch...
scanf("%c", &Instruct1);
scanf("%c", &Instruct2);
switch(Instruct2) {
case'A':case'a': {
ERPSGame();
This could be giving you an odd value given the fact that users response is in instruct1. Potentially.
In the code below, if the user enters 1 or 2, everything proceeds smoothly.
But if I enter anything else besides 1 or 2, the loop runs, but an additional is required to continue the loop.
How do I eliminate the need for this ?
#include <stdio.h>
#include <ctype.h>
#include <math.h>
void clearKeyboardBuffer() {
int ch;
while ((ch = getchar() != '\n') && (ch != EOF));
}
void entry1(){
char chArr[BUFSIZ];
char choice, ch;
int choiceint, rating;
do{
printf("1.\tZoo\n2.\tMall\n3.\tExit\n\n");
printf("Choose a place by entering its numerical value: ");
fgets(chArr,sizeof(chArr),stdin);
sscanf(chArr, " %c", &choice);
// converts scanned char to int
choiceint = choice - '0';
if(!isdigit(choice) || choiceint > 3){
printf("You did not enter an accepted digit.\n");
}
else if(choiceint != 3){
switch(choiceint){
case 1:
printf("You chose the Zoo.\n");
printf("your rating : ");
scanf("%d", &rating);
break;
case 2:
printf("You chose the Mall.\n");
printf("your rating : ");
scanf("%d", &rating);
break;
}// end of switch
}// end of else if
else{
}// end of else
clearKeyboardBuffer();
}// end of do
while(choiceint !=3);
}
just move the call to clearKeyboardBuffer() right after //end of switch as in
char chArr[BUFSIZ];
char choice, ch;
int choiceint, rating;
do{
printf("1.\tZoo\n2.\tMall\n3.\tExit\n\n");
printf("Choose a place by entering its numerical value: ");
fgets(chArr,sizeof(chArr),stdin);
sscanf(chArr, " %c", &choice);
// converts scanned char to int
choiceint = choice - '0';
if(!isdigit(choice) || choiceint > 3){
printf("You did not enter an accepted digit.\n");
}
else if(choiceint != 3){
switch(choiceint){
case 1:
printf("You chose the Zoo.\n");
printf("your rating : ");
scanf("%d", &rating);
break;
case 2:
printf("You chose the Mall.\n");
printf("your rating : ");
scanf("%d", &rating);
break;
}// end of switch
clearKeyboardBuffer();
}// end of else if
else{
}// end of else
}// end of do
while(choiceint !=3);
You've got a problem with your if else loop. If the choice is not a digit or >3 you want to re-ask the user
#include <stdio.h>
#include <ctype.h>
#include <math.h>
void clearKeyboardBuffer() {
int ch;
while ((ch = getchar() != '\n') && (ch != EOF));
}
void entry1(){
char chArr[BUFSIZ];
char choice, ch;
int choiceint, rating;
do{
printf("1.\tZoo\n2.\tMall\n3.\tExit\n\n");
printf("Choose a place by entering its numerical value: ");
fgets(chArr,sizeof(chArr),stdin);
sscanf(chArr, " %c", &choice);
// converts scanned char to int
choiceint = choice - '0';
if(!isdigit(choice) || choiceint < 1 || choiceint > 3){
printf("You did not enter an accepted digit.\n");
}
// If 0 > choice > 3
else {
switch(choiceint){
case 1:
printf("You chose the Zoo.\n");
printf("your rating : ");
scanf("%d", &rating);
break;
case 2:
printf("You chose the Mall.\n");
printf("your rating : ");
scanf("%d", &rating);
break;
case 3:
break;
default:
break;
}// end of switch
}// end of else
clearKeyboardBuffer();
}// end of do
while(choiceint !=3);
}