The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
untitled C Code
Posted by: C crap | December 22, 2010 @ 11:21pm
C Code
[
Download
]
#include <stdio.h> #include <stdlib.h> #include <conio.h> #include <string.h> //#include <string> #include <ctype.h> #include <time.h> #include <math.h> #include <iostream> //using namespace std; void menu(); char get_choice(); void ChangeUtl(); void HighLow(); void menu(int CCC, int HLC, int HLT) { system("cls"); int HLA = 0; if (HLC != 0) { HLA = HLT / HLC; } else printf( "A. Change Count "); std::cout<<"Used "<<CCC; std::cout<<" Times"<<std::endl; printf( "B. High Low "); std::cout<<"Used "<<HLC; std::cout<<" Times. Averaging "<<HLA; std::cout<<" Tries."<<std::endl; printf( "Q. Quit Program\n"); printf( "\n\n\n" ); printf( ":" ); } void main(int TTT) { char choice; int CCC = 0; int HLC = 0; int HLT = 0; do { menu(CCC, HLC, HLT); choice = get_choice(); switch(choice) { case 'A': CCC = CCC + 1; ChangeUtl(); break; case 'B': HLC = HLC + 1; HighLow(); break; } } while(choice != 'Q'); } char get_choice() { char ch; do { ch = toupper(_getch()); } while (!strchr("ABQ",ch)); return ch; } void ChangeUtl() { system("cls"); int pcd, ncd, dcd, qcd, hcd, totalc; double pvd, nvd, dvd, qvd, hvd, total; std::cout<<"Enter the Number of Pennies: "; std::cin>>pcd; std::cout<<std::endl; std::cout<<"Enter the Number of Nickles: "; std::cin>>ncd; std::cout<<std::endl; std::cout<<"Enter the Number of Dimes: "; std::cin>>dcd; std::cout<<std::endl; std::cout<<"Enter the Number of Quarters: "; std::cin>>qcd; std::cout<<std::endl; std::cout<<"Enter the Number of Half Dollar: "; std::cin>>hcd; std::cout<<std::endl; pvd = pcd * 0.01; nvd = ncd * 0.05; dvd = ncd * 0.1; qvd = qcd * 0.25; hvd = hcd + 0.5; total = pvd + nvd + dvd + qvd + hvd; totalc = pcd + ncd + dcd + qcd + hcd; std::cout<<"You Entered "<<pcd; std::cout<<" Pennies for: $"<<pvd<<std::endl; std::cout<<"You Entered "<<ncd; std::cout<<" Nickels for: $"<<nvd <<std::endl; std::cout<<"You Entered "<<dcd; std::cout<<" Dimes for: $"<<dvd <<std::endl; std::cout<<"You Entered "<<qcd; std::cout<<" Quarters for: $"<<qvd<<std::endl; std::cout<<"You Entered "<<hcd; std::cout<<" Half Dollars for: $"<<hvd<<std::endl; std::cout<<"You Entered "<<totalc; std::cout<<" Coins worth a total of: $"<<total<<std::endl; _getch(); } void HighLow() { #define MAX 5 int magic, // number generated by the computer guess, // players guess tries = 0; // total number of guesses srand( (unsigned)time( NULL ) ); // seed the random number table magic = rand()%MAX; //return a random number from 0 to MAX system("cls"); //printf("magic:%d ",magic); //this line can be used for debugging printf("\n\nGuess the random number from 0 to %d\n",MAX); printf("Guess 9 to exit.\n\n\n"); do { printf("Guess: "); scanf("%d",&guess); if(guess == magic) { printf("** Right **"); printf("%d is the magic number\n", magic); } else if(guess == 9) { magic = guess; printf("Quiting......"); } else if (guess > magic) printf(".. Wrong .. Too High\n"); else printf(".. Wrong .. Too Low\n"); tries++; } while(guess != magic); HLT = HLT + tries; printf("You took %d tries.\n", tries); printf("\n\n\n\nPress any key to end"); // modify this line so the user knows they are // returning to the menu and so I know you are //reading this stuff ;) _getch(); }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.53 / 8
81 Votes
http://codebin.yi.org/1032
page generated in 0.00 seconds