r/programminghomework • • Dec 22 '20

Yes hello everyone, i need help.

so i need to program this problem using the "c" programming language. Ignore the red text that's crossed out and ignore any question that isn't about the programming.

https://prnt.sc/w65egi

https://prnt.sc/w65ex2

https://prnt.sc/w65fxa

https://prnt.sc/w65g6r

So far i've only done up to section A but the program won't run. Here's what my code looks like

#include <stdio.h>

#include <stdlib.h>

//gn= guest number, l= length, s= smoker, ccn= credit card number

int main()

{

int gn, l, ccn, i, s,cnt;

printf("Enter Guest Number\\n");

scanf("%d", gn);

while(gn != -1)

{

	printf("Please Enter Name\\n");

	scanf

	printf("Enter length of stay\\n");

	scanf("%d", l);

	if (l > 7)

	{

		printf("You can only stay for 7 days\\n");

		printf("Enter length of stay");

		scanf("%d", l);

	}

	

	printf("If you smoke please enter 1\\n");

	scanf("%d", s);

	if(s = 1)

	{

		printf("Smoker.");

	}

	else

	{

		printf("Non-Smoker");

	}

	}

	if
}

return 0;

}

(sorry if this is too much on the eyes, don't know how to make it colored)

1 Upvotes

3 comments sorted by

2

u/Solidu_Snaku Dec 23 '20 edited Dec 23 '20

A few things are wrong, try this: https://pastebin.com/2gf8VaKX

Firstly, the first scanf is wrong it is not taking any type of data, not putting it to any variable and it is not terminated with a semicolon. "scanf" becomes "scanf(%s, Name);" and we have to then declare the Name variable next to the other declared variables.

Then you need to delete the "} if" at the end. Also turn all the "\\n" into "\n" that seems to work better for me.

I have never programmed in C but I think it's a good starting point maybe

1

u/ShadowZeno1 Dec 23 '20

it's accepting the gn but then after that the process stops. I'm assuming it has something to do with the "while(gn != -1)" line of code. Is there another way of stopping the loop using -1?

1

u/Solidu_Snaku Dec 23 '20

Try "scanf(%d, &gn);"