Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 11661

I'm having an issue with getting my decimal format correct

$
0
0

I'm a CS student working on a project to convert a number to a decimal then to a rounded whole number.

int main(int argc, char** argv){        //Problem 1- Output a score    int score = 34567;    printf("Score %d\n", score);        //Problem 2- Output a percentage    float percent = (float)score / MAX_SCORE;    printf("Percentage %.2f\n", percent);        //Problem 3- Output a rounded percentage    int rPercent = (int)percent;    printf("Rounded Percentage %d\n", rPercent);    return (EXIT_SUCCESS);

I get the code to run as is but don't get the result I am looking to achieve. My "score" int is set to 34567, I require the percent to show as a 4 digit float (34.57), and then a rounded percentage (35). The problem I keep running into is that my percent outputs as (.35). Is it a problem in problem 2 of my code?


Viewing all articles
Browse latest Browse all 11661

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>