r/code • • May 25 '20

What is wrong with my code!? Unused but set variable.

Post image
11 Upvotes

13 comments sorted by

2

u/[deleted] May 25 '20

Looks like your subtracting strings, will be an invalid operation.. remove some quotes

0

u/friday550 May 26 '20

Not subtracting strings. Supposed to print what’s in quotes and leave the rest alone

8

u/untermenschausrussia May 25 '20

printf doesn’t work this way, check how you used scanf.

3

u/Jackplox May 25 '20

use %d when using the printf statement in place of the variable names

eg

printf(“(%d) %d - %d”, areaCode, prefixCode, lineCode);

(cant see your variables, so put the corresponding ones in the right order)

1

u/StochasticTinkr May 26 '20

Use “(%03d) %03d-%04d” instead. It shouldn’t matter for the area code/prefix, but definitely will for the suffix.

Without the 04, the phone number 2347890054 would print out as (234) 789-54

1

u/Jackplox May 26 '20

ah good catch

2

u/malicart May 26 '20

Real answer is this is the wrong sub, try a learning one related to your language of choice.

1

u/[deleted] May 26 '20

To print quotes as a valid character use "

1

u/justingolden21 May 26 '20

Should it say long long on line 4

1

u/Poddster May 26 '20

Hopefully this doesn't compile?

1

u/StochasticTinkr May 26 '20

When working in the real world, Store phone numbers as strings, not long long. Real phone numbers have all kinds of crazy formats.

I know that isn’t relevant to your situation, but though it’s worth mentioning for the future.

1

u/[deleted] May 26 '20

Unnecessary maths, just use string manipulation. If you are always given a 10 digit number as input... this is almost a one liner