Sunday, July 12, 2009

Can someone please check this code for me it is in C programing due today so please hurry?

#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;


#include %26lt;time.h%26gt;


#include %26lt;conio.h%26gt;


#include %26lt;ctype.h%26gt;





int main (void)


{


//creating random balance for user


srand(time(NULL));


int ranBal;


ranBal = rand();





printf("\t\t Virtual Bank at Osceola\n");


printf("\t\t\t WELCOME\n\n");





char num1, num2, num3, num4;


printf("Please enter you 4 digit pin number: \n");


scanf("%c%c%c%c", %26amp;num1, %26amp;num2, %26amp;num3, %26amp;num4);





//Pin number code


for (int count = 0; count %26lt; 4; count++)


{


if (count == 3)


{


printf("Sorry You can't continue, contact your bank for assistance");


}


if ((isdigit(num1)) %26amp;%26amp; (isdigit(num2)) %26amp;%26amp; (isdigit(num3)) %26amp;%26amp;(isdigit(num4)))


{


printf("Valid Pin");


break;


}//end if


else


{


printf("Invalid Pin");


printf("Please try to enter your pin again");


scanf("%c%c%c%c", %26amp;num1, %26amp;num2, %26amp;num3, %26amp;num4);


}//end else





}//end for





int receipt;


printf("For Receipt enter 1, For no receipt enter 2\n");


scanf("%d", %26amp;receipt);


if (receipt == 1)


printf("Please take your receipt\n");


else if (receipt == 2)


printf("No receipt will be printed\n\n");


else


printf("Invalid Entry\n");








//clear screen


//clrscr();





int again = 1;


int option;





while (again == 1)


{


printf("Please choose one of the following numbers\n\n");


printf("1: Get Card Back 2: Fast Cash 3: Withdraw 4: Deposit 5: Balance\n\n");


scanf("%d", %26amp;option);





int fastCash;





if (option == 1)


{


printf("Goodbye!\n\n");


}//end option 1


printf("Press 1: Another Transaction or Press 2: Get Card Back");


scanf("%d", %26amp;again);


else if (option == 2)


{


printf("1: $20.00 2: $40.00 3: $80.00 4: $100.00\n\n");


scanf("%d", %26amp;fastCash);


if (fastCash == 1)


{


printf("You have withdrawn $20.00\n");


}


if (fastCash == 2)


{


printf("You have withdrawn $40.00\n");


}


if (fastCash == 3)


{


printf("You have withdrawn $80.00\n");


}


if (fastCash == 4)


{


printf("You have withdrawn $100.00\n");


}





printf("Press 1: Another Transaction or Press 2: Get Card Back");


scanf("%d", %26amp;again);


}//end option 2


else if (option == 3)


{


int withdrawl;


printf("Please enter withdrawl amount\n");


scanf("%d", withdrawl);


ranBal = ranBal - withdrawl;


if (ranBal %26lt; 0)


printf("");


//compare to actual balance which must be a randomized number


printf("Press 1: Another Transaction or Press 2: Get Card Back");


scanf("%d", %26amp;again);


}//end option 3


else if (option == 4)


{


printf("Please enter deposit amount\n");


printf("Press 1: Another Transaction or Press 2: Get Card Back");


scanf("%d", %26amp;again);


}//end option 4


else if (option == 5)


{


printf("Your balance is %d.\n", ranBal);


printf("Press 1: Another Transaction or Press 2: Get Card Back");


scanf("%d", %26amp;again);


//just print off randomized balance number


}//end option 5


else


{


printf("Invalid Entry\n");


printf("Press 1: Another Transaction or Press 2: Get Card Back");


scanf("%d", %26amp;again);


}





}





if (again == 2)


printf("Goodbye!");





if ((again != 1) %26amp;%26amp; (again != 2))


printf("Invalid Entry");





system("pause");


return (0);


}//end main

Can someone please check this code for me it is in C programing due today so please hurry?
I stopped reading after this line:





char num1, num2, num3, num4;


printf("Please enter you 4 digit pin number: \n");


scanf("%c%c%c%c", %26amp;num1, %26amp;num2, %26amp;num3, %26amp;num4);





which is so hopelessly messed up, I had to laugh for a few hours.





Anyway, there is no way to judge this program since you just threw code at us and not what it is supposed to do. So yeah, this code looks perfect, just like any other code someone might post.
Reply:That program is screwed up in more ways than a dozen. Good luck. You need to talk to your professor and tell her or him to help you. Your professor has obviously not communicating with you on how to write a program.





RJ
Reply:This must be for a university course.





It's hard to read because it's all crammed over to the left.


Review the use of indention, and ANSI standards.





Also, you have everything in the main function which also makes it hard to read, too much in one function.
Reply:Couple of things -





for (int count = 0; count %26lt; 4; count++) - what exactly is this for loop for? You should probably be using a switch statement.
Reply:Can you try with system("CLS") ; instead of clescr();


No comments:

Post a Comment