1. Do/While Loops

Hi, guys! First post here.

I'm doing this project for the hell of it and I am improvising a lot of stuff to accommodate what would REALLY happen in most cases.

So, this calculates mileage. Everything is fine until the bottom with the Do/While loops. I don't know the best way to do Y/N situations. Could I call on you to educate me on why these Do/While loops are not placed correctly? Thanks in advance!

EDIT: I'm adding in the way I coded the heading variables just for verification.
Code:
```	double start_mile,
end_mile;
double reimbursement = .35;
char mile_yn; /* Mile Yes/No for Below */
char reim_yn /* Reimbursement Loop Killer */```
Code:
```int mile_calc()
{
/* You Show Off */
printf("\nMile Reimbursement Calculator");
printf("\nVersion 1.0.001");

/* Starting Mileage */
scanf("%.1f", &start_mile);

/* Ending Mileage */
scanf("%.1f", &end_mile);

do
{
printf("Current Reimbursement: ", reimbursement);
printf("\nIs this correct(Y/N)?");
scanf("%c", &mile_yn);

if (mile_yn = "Y")
printf("Calculating...\n");

if (mile_yn = "N")
printf("Enter the New Reimbursement Rate: ");
scanf("%.2f", reimbursement);
printf("New Reimbursement: ", reimbursement);
printf("\nIs this correct(Y/N)?");

if (mile_yn = "y")
printf("Calculating...\n");

if (mile_yn = "n")
printf("Enter the New Reimbursement Rate: ");
scanf("%.2f", reimbursement);
printf("New Reimbursement: ", reimbursement);
printf("\nIs this correct(Y/N)?");
scanf("%c", &reim_yn);
}
while ( reim_yn ("N"));

}```

2. One of the first pitfalls in C is scanf().

It works as expected for numbers, and strings, but not for single char's.

After you take in a char with scanf(), you leave a newline char ('\n'), at the head of the keyboard buffer.

Now when scanf() goes to look for the next single char, it see's this old newline char, and says "Great, I've found my char!", and rolls on. It will look your code is "skipping" over the scanf(), completely.

Two fixes:

1) add a variable = getchar() before each scanf() for a single char, or

not this:
Code:
`scanf("%c", &myChar);`
but this:
Code:
`scanf(" %c", &myChar);`
Note the single extra space, before the second % sign. Makes all the difference.

Note that I did not look at the rest of your code, after I saw the scanf() for a single char, in it. This is a *very* frequent problem for new programmers in C.

3. Well, I fixed those references, but apparently the IF statements aren't working correctly. I'm getting tons of errors about them and about the operands used. How do I get a correct IF statement for when one of my values = Y or N?

4. With this statement,

if (mile_yn = "Y")

You are wanting to compare variable mile_yn (a char? a char array?) with a string constant.

But, you aren't. Instead you are (trying to) assign ( = ) a string to the variable mile_yn. And, that's not the proper way to assign a string to a variable.

5. Originally Posted by sinamor1210
Well, I fixed those references, but apparently the IF statements aren't working correctly. I'm getting tons of errors about them and about the operands used. How do I get a correct IF statement for when one of my values = Y or N?
Code:
```if (mile_yn = "Y")
printf("Calculating...\n");```
'Y' is a char but this is a char array(string) "Y". So what you're doing is taking in char from the user and in the if statement assigning that char to string, which is incorrect. So the correct solution would be to compare(==) the inputted char with 'Y'(or 'N').

One of the first pitfalls in C is scanf().

It works as expected for numbers, and strings, but not for single char's.

After you take in a char with scanf(), you leave a newline char ('\n'), at the head of the keyboard buffer.

Now when scanf() goes to look for the next single char, it see's this old newline char, and says "Great, I've found my char!", and rolls on. It will look your code is "skipping" over the scanf(), completely.

Two fixes:

1) add a variable = getchar() before each scanf() for a single char, or

not this:
Code:
`scanf("%c", &myChar);`
but this:
Code:
`scanf(" %c", &myChar);`
Note the single extra space, before the second % sign. Makes all the difference.

Note that I did not look at the rest of your code, after I saw the scanf() for a single char, in it. This is a *very* frequent problem for new programmers in C.
solved one of my other problem because of which I joined here.

Thanks scanf was also not working for me

7. you can after each scanf add a function which eats line for example
while(getchar()!='\n')
continue;
will skip every thing after scanf like for example you type more than a answer
like NOOO
will only read N so it can be usefull sometimes and a single char is 'C' not "C"