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
sup
Posted by: will | October 14, 2009 @ 9:29pm
C Code
[
Download
]
#include <stdio.h> #include <stdlib.h> #include "mathMaster.h" int main() { FILE *score; double x; double y; double z; int c; int scores; scores = 0; while (1) { printf( "Enter 's' to input two double values, and the sum of these values: \n"); printf( "Enter 'p' to input two double values, and the product of these values: \n"); printf( "Enter 'd' to input two double values, and the difference of these values: \n"); printf( "Enter 'm' to input two double values, and the maximum of these values: \n"); printf( "Enter 'n' to input two double values, and the minimum of these values: \n"); printf("Enter 'q' to quit.\n"); c = getchar(); while (getchar() != '\n') { ; } if ((c == 'q') || (c == 'Q')) { /* Checking if user chose to quit program */ if ((score = fopen("a4.score", "r")) != NULL) { fprintf(stderr, "Score file exists, would you like to overwrite? (Y/N)\n "); c = getchar(); } while (getchar() != '\n') { ; } if (fclose(score) == EOF) { fprintf(stderr, "File cannot close properly\n"); return EXIT_FAILURE; } if (!(c == 'y' || c == 'Y')) { fprintf(stderr, "Leaving score file untouched, terminating program.\n"); return EXIT_SUCCESS; } if ((score = fopen("a4.score", "w")) == NULL) { fprintf(stderr, "Cannot open scores. \n"); return EXIT_FAILURE; } fprintf(score, "Your score is: %d", scores); if (fclose(score) == EOF) { fprintf(stderr, "Unable to close score file\n"); return EXIT_FAILURE; } printf("Cya Later ! Thank's for participating! \n"); return EXIT_SUCCESS; } if (scanf("%lf%lf%lf", &x, &y, &z) != 3) { /* Checking to make sure correct input form */ fprintf(stderr, "Invalid Input.\n"); return EXIT_FAILURE; /* If wrong input, program exits */ } if (mathMaster(c, x, y, z)) { /* If the user is correct , according to mathMaster function, then scores is increased */ scores++; } } return EXIT_SUCCESS; }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.52 / 8
79 Votes
http://codebin.yi.org/414
page generated in 0.01 seconds