Skip to content

Commit de28a28

Browse files
authored
Refactor Love-Calculator
1 parent 261c1a7 commit de28a28

File tree

1 file changed

+59
-71
lines changed
  • Windows_System_examples/Love-Calculator

1 file changed

+59
-71
lines changed

Windows_System_examples/Love-Calculator/main.c

Lines changed: 59 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,79 @@
11
#include <stdio.h>
22
#include <stdlib.h>
3-
#include<conio.h>
4-
int main()
3+
4+
5+
void enter_string(char* message, char* s, size_t s_size) {
6+
printf("%s", message);
7+
fgets(s, s_size, stdin);
8+
}
9+
10+
int get_score(char* s)
511
{
6-
int i,a2,g=0,p,a1,s2=0,b,s1=0;
7-
char s[1000],st[1000];
8-
printf("Enter The First Name: ");
9-
fgets(s, sizeof(s), stdin);
10-
for ( i = 0; s[i] != '\0'; i++);
11-
a1=i-1;
12-
printf("Enter The Second Name: ");
13-
fgets(st, sizeof(st), stdin);
14-
for ( i = 0; st[i] != '\0'; i++);
15-
a2=i-1;
16-
for(int j=0;j<a1;j++)
17-
{
18-
b=(int) s[j];
19-
20-
if(s[j]==' ')
12+
char *end;
13+
for (end = s; *end != '\0'; ++end);
14+
--end;
15+
16+
if (end == s)
2117
{
22-
continue;
18+
printf("wrong Input\n");
19+
return -1;
2320
}
24-
else if(s[j]>='A'&&s[j]<='Z')
25-
{
26-
s1=s1+(b-64)*5;
27-
}
28-
else if(s[j]>='a'&&s[j]<='z')
21+
22+
int score = 0;
23+
char c;
24+
for(char* p = s; p != end; ++p)
2925
{
30-
s1=s1+(b-96)*5;
31-
}
26+
c = *p ^ 0x20;
27+
28+
if(c == ' ')
29+
{
30+
continue;
31+
}
32+
else if(c >= 'A' && c <= 'Z')
33+
{
34+
score += c - '@';
35+
}
3236
else
3337
{
3438
printf("wrong Input\n");
35-
g=12;
36-
break;
37-
}
38-
39+
return -1;
40+
}
41+
}
42+
return score * 5 / (end - s);
3943
}
40-
s1=s1/a1;
4144

45+
int main()
46+
{
47+
int p,s1,s2;
48+
char name[1000];
4249

43-
for(int j=0;j<a2;j++)
44-
{
45-
b=(int) st[j];
46-
47-
if(st[j]==' ')
50+
while(1)
4851
{
49-
continue;
50-
}
52+
do
53+
{
54+
enter_string("Enter The First Name: ", name, sizeof(name));
55+
s1 = get_score(name);
56+
} while (s1 == -1);
5157

52-
else if(st[j]>='A'&&st[j]<='Z')
53-
{
54-
s2=s2+(b-64)*5;
55-
}
56-
else if(st[j]>='a'&&st[j]<='z')
57-
{
58-
s2=s2+(b-96)*5;
59-
}
58+
do
59+
{
60+
enter_string("Enter The Second Name: ", name, sizeof(name));
61+
s2 = get_score(name);
62+
} while (s2 == -1);
63+
64+
if(s2 > s1)
65+
{
66+
p = (s1 * 100) / s2;
67+
}
6068
else
6169
{
62-
printf("wrong Input\n");
63-
g=12;
64-
break;
65-
}
66-
67-
}
68-
s2=s2/a2;
70+
p = (s2 * 100) / s1;
71+
}
6972

70-
if(g!=12)
71-
{
72-
if(s2>s1)
73-
{
74-
p=(s1*100)/s2;
75-
}
76-
else
77-
{
78-
p=(s2*100)/s1;
79-
}
80-
char ch='%';
81-
printf("The love Percentage is : %d %c\n",p,ch);
82-
}
83-
else
84-
{
85-
printf("Input Error\n");
86-
}
87-
printf("\n pls Follow me 🌟 if you like this code 😊\n");
88-
return main();
73+
printf("The love Percentage is : %d %% \n",p);
74+
printf("\n pls Follow me 🌟 if you like this code 😊\n");
75+
}
76+
return 0;
8977
}
9078

9179

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy