Created
March 23, 2011 10:01
-
-
Save adammw/882886 to your computer and use it in GitHub Desktop.
HIT2080 Lab 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* FILE: tasks4.c | |
* Author: Adam Malcontenti-Wilson <9509453@student.swin.edu.au> | |
* Last Modified: 17/03/2011 12:20:00 PM | |
* | |
* Description: Printing hard-coded scores | |
* Inputs: none | |
* Outputs: Text in specifc format specified | |
*/ | |
#include <stdio.h> | |
int main() { | |
printf("Score: %3i %45s Player: %3s\n",0,"","AAA"); | |
printf("%24sCoordinates: (%2i, %2i)%12sAlive: %c\n","",1,12,"",'y'); | |
printf("Total Damage: %3i%31sHits per turn: %5.2f\n",134,"",1.23); | |
printf("Time Remaining: %6.2f seconds%14sPlayer Advantage: %+3.1f\n",-23.01,"",87.2); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* FILE: task5.c | |
* Author: Adam Malcontenti-Wilson <9509453@student.swin.edu.au> | |
* Last Modified: 17/03/2011 12:22:00 PM | |
* | |
* Description: Printing scores and stats from variables | |
* Inputs: none | |
* Outputs: Text in specifc format specified | |
*/ | |
#include <stdio.h> | |
int main() { | |
int score = 0; | |
char player[4] = "AAA"; | |
int x = 1; | |
int y = 12; | |
char alive; | |
int damage; | |
double hits; | |
double time; | |
double advantage; | |
alive = 'y'; | |
damage = 134; | |
hits = 1.23; | |
time = -23.01; | |
advantage = 87.2; | |
printf("Score: %3i %45s Player: %3s\n",score,"",player); | |
printf("%24sCoordinates: (%2i, %2i)%12sAlive: %c\n","",x,y,"",alive); | |
printf("Total Damage: %3i%31sHits per turn: %5.2f\n",damage,"",hits); | |
printf("Time Remaining: %6.2f seconds%14sPlayer Advantage: %+3.1f\n",time,"",advantage); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* FILE: task6.c | |
* Author: Adam Malcontenti-Wilson <9509453@student.swin.edu.au> | |
* Last Modified: 17/03/2011 12:22:00 PM | |
* | |
* Description: Printing scores and stats from variables and entered numbers with data validation | |
* Inputs: damage(int), hits(double) | |
* Outputs: Text in specifc format specified | |
*/ | |
#include <stdio.h> | |
/* | |
* Function to flush the input buffer when invalid data type entered | |
* Source: http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1044873249&id=1043284392 | |
*/ | |
void flush() { | |
char ch; | |
while ((ch = getchar()) != '\n' && ch != EOF); | |
} | |
/* | |
* Main function | |
*/ | |
int main() { | |
/* Declare variables*/ | |
int score = 0; | |
char player[4] = "AAA"; | |
int x = 1; | |
int y = 12; | |
char alive; | |
int damage = -1; | |
double hits = -1; | |
double time; | |
double advantage; | |
alive = 'y'; | |
time = -23.01; | |
advantage = 87.2; | |
/* Ask user for valid damage amount*/ | |
do { | |
printf("Enter the amount of damage: "); | |
if (!scanf("%i",&damage)) { | |
flush(); | |
damage = -1; | |
} | |
if (damage < 0 || damage > 999) { | |
printf ("\nInvalid input. Please enter a whole number between 0 and 999\n"); | |
} | |
} while (damage < 0 || damage > 999); | |
/* Ask user for valid hits amount */ | |
do { | |
printf("\nEnter the amount of hits: "); | |
if (!scanf("%lf",&hits)) { | |
flush(); | |
hits = -1; | |
} | |
if (hits < 0 || hits > 10) { | |
printf ("\nInvalid input. Please enter a decimal number between 0 and 10\n"); | |
} | |
} while (hits < 0 || hits > 10); | |
/* Print scores output */ | |
printf("\nScore: %3i %45s Player: %3s\n",score,"",player); | |
printf("%24sCoordinates: (%2i, %2i)%12sAlive: %c\n","",x,y,"",alive); | |
printf("Total Damage: %3i%31sHits per turn: %5.2f\n",damage,"",hits); | |
printf("Time Remaining: %6.2f seconds%14sPlayer Advantage: %+3.1f\n",time,"",advantage); | |
/* Return successful */ | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* FILE: tasks1-3.c | |
* Author: Adam Malcontenti-Wilson <9509453@student.swin.edu.au> | |
* Last Modified: 17/03/2011 12:00:00 PM | |
* | |
* Description: A simple program printing my name, left-justified | |
* Inputs: none | |
* Outputs: Text (name, student ID and email) left-justified on the DOS screen | |
*/ | |
#include <stdio.h> | |
int main() { | |
printf("%-s\n\n\n","Adam Malcontenti-Wilson"); | |
printf("%7s\n\n","9509453"); | |
printf("%s","9509453@student.swin.edu.au"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment