scanf_s correct input counter

I just want it to count correct inputs (3),but it asks for input 6 times (3 times in Line 11 and 3 times in if statement).
i would appreciate any help.
Thanks in advance.

p.s. Don't mind the strings they are there just to guide users.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  #include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define _CRT_SECURE_NO_WARNINGS

int main()
{
	int CP, P1, P2, br;
	float C1;
	printf("Unesi pocetnu cenu, porez i popust..");
	scanf_s("%d%d%d", &CP, &P1, &P2);
	if (scanf_s("%d%d%d", &CP, &P1, &P2) == 3)
	{
		C1 = CP + (CP / 100.*P1);
		C1 = C1 - (C1 / 100.*P2);
		if (C1 > CP)
			printf("Akcijska cena je veca od pocetne.");
		else if (CP > C1)
			printf("Akcijska cena je manja od pocetne.");
		else
			printf("Cene su iste.");
	}
	else
		printf("Neispravan unos.");
	system("pause");
	return 0;
}
Last edited on
The problem is that line 11 calls scanf_s() and then line 12 calls it again. To fix this, just remove line 11.
Thanks, I get it now.
Topic archived. No new replies allowed.