I would like to do the following, but I get an error.
$./a.out
Principal (yen): 1000000
% annual interest rate: 0.001
Deposit period (year): 10
Year 1: 1000010 Yen
Year 2: 1000020 Yen
Year 3: 1000030 Yen
Year 4: 1000040 Yen
Year 5: 1000050 Yen
Year 6: 1000060 Yen
Year 7: 1000070 Yen
Year 8: 1000080 Yen
Year 9: 1000090 Yen
Year 10: 1000100 Yen
I got an error when I programmed as follows.
int main (void)
{
inti, m, n, y;
printf("Principal: ");
scanf("%d", & m);
printf("Annual interest rate (%):");
scanf("%d", & n);
printf("Deposit Period (Year):");
scanf("%d", & y);
for(i=m;i<=y;i=i+n/100){
printf("Year i: %d Yen\n", i );
}
return 0;
}
ex0304.c:In function 'main':
ex0304.c:8:24:warning:unknown conversion type character') 'in format [-Wformat=]
printf("Annual interest rate (%):");
^
Do not use %
alone in printf
or in format strings in scanf
.You must have at least one known character after you.Same as \
in the general string.
If you want the percentage character %
to appear on the screen, it's printf("%d%%",100);
.
printf
requires the %
symbol followed by the type specifier (the "d" or "c" part in the example below).
Example:
printf("%d", num);## decimal
printf("%s",str);## string
However, where the warning appears, the %
symbol is written as (%)
, which is considered to be an unknown type designation of %)
.
If you want to print the %
symbol as a character in printf
, write it like %%
.
printf("%d%%,num);
Also, there are several wrong parts besides the warning, so I don't think it will work as expected even if only the printf
part is corrected.
"By the way, @cubick said ""there are several wrong parts besides the parts where warning is displayed""
0.001
for the annual interest rate, the next deposit period (year): will be skipped, and the for
loop will not run and will end without display as shown below.)for
The control portion of the loop is a mixture of loop count control and interest rate calculation, making it meaningless and never running.Let's think carefully.
© 2024 OneMinuteCode. All rights reserved.