Skip to content

Instantly share code, notes, and snippets.

@casspangell
Last active January 4, 2016 21:19
Show Gist options
  • Save casspangell/8679988 to your computer and use it in GitHub Desktop.
Save casspangell/8679988 to your computer and use it in GitHub Desktop.
write a function that prints a rating between zero and four stars. ratings can be half stars (two and a half for example). full stars should be represented by an asterisk (*) and half stars should be represented by a period (.)
(NSString*)ratingFunction(int):rating{
int halfStars = rating - floor(rating);
int fullStars = floor(rating);
NSString *rateString;
while(fullStars > 0){
rateString = [rateString stringByAppendingString:@"*";
fullStars --;
}
if(halfStars != 0){
rateString = [rateString stringByAppendingString:@".";
}
return rateString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment