Hey guys, I've been following the CS50 lectures online to help teach me C. I'm understanding most of it so far but I'm very stuck on a small part of problem set 1. It involves displaying a variable in the form of currency. I've had a look around via google and have some ideas about what I can do. It's currently a long long variable, and I was thinking of converting it to a string with the format {0;C} but its either not possible or I'm really struggling with the code. Can someone please realign my thinking on the right track? Or any help at all would be great!!!
A brief snippet of my code:
- Code: Select all
printf("Now please input the number of pennies you receive: ");
float p = GetFloat();
if(p > 0)
{
p = (p/100);
long long r = p * pow(2,m);
printf("For %d days with a start of $%.2f, the total is $%lld!\n",m, p, r);
ans2 = false;
ans1 = false;
}
Currently the long long r is displayed in %lld format. I ideally need to add comma thousand spacing and 2 decimals after.
Again any help would be appreciated. Thanks!