0

This is the output I am recieving. I am unable to enter the name of the suite and the program ends after it.I am trying to make a program in C which will ask the user their preferred suite and additional services and later on calculate their cost of stay. However my program exits with a warning and does not let the user enter an input suite. I have included the code below. It is incomplete and I still have to write the method will calculate the cost. My only concern is that why is my program not taking user input?

'''

#include <stdio.h>
#include <stdlib.h> 
void main()
{
    printf("Welcome to La Quinta Palm Springs\n");
    printf("Below mentioned are the various suites available here\n");
    printf("_________________________________________________________________________________\n");
    printf("Gold Suite\n");
    printf("Cost per night: 7000 Rs.\n");
    printf("Inclusions: Breakfast, wifi, Airport Transportation\n");
    printf("Cost for aditional services:\n");
    printf("Laundry: 400 Rs per day\n");
    printf("Lunch 1500 Per Person\n");
    printf("Brunch 700 Per Person ");
    printf("Dinner 2000 Per Person ");

    printf("Silver Suite\n");
    printf("Cost per night: 5000 Rs.\n");
    printf("Inclusions: Breakfast, wifi, Airport Transportation\n");
    printf("Cost for aditional services:\n");
    printf("Laundry: 400 Rs per day\n");
    printf("Lunch 1300 Per Person\n");
    printf("Brunch 500 Per Person \n");
    printf("Dinner 1500 Per Person \n");

    char suite[9], laundry[3];
    int nperson,nnights,nrooms,nPerRoom;
    printf("Enter your preferred suite:  ");
    scanf('%s',suite);
    printf("For how many nights do you plan to stay? :");
    scanf('%d',&nnights);
    printf("Please enter the number of persons staying in one room: ");





}

'''

lord foul
  • 19
  • 3
  • 1
    You must have missed something in your tutorial or text-book about the `scanf` function. Just like `printf` it excepts the formatt string to be an actual *string*. – Some programmer dude Mar 12 '21 at 04:24
  • 2
    And for future questions, please don't show images of errors, copy-paste the text *as text* into the question. – Some programmer dude Mar 12 '21 at 04:25
  • 1
    You may want to read this: [Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/q/285551/12149471) – Andreas Wenzel Mar 12 '21 at 04:31
  • 1
    You should change `scanf('%s',suite);` to `scanf("%s",suite);`. The former specifies a character literal, whereas the latter specifies a string literal. You need to pass a string as the first argument to `scanf`, not a character. You made the same mistake in the second `scanf` function call. – Andreas Wenzel Mar 12 '21 at 04:38
  • 1
    `'%s'` --> `"%8s"` Save time, enable all compiler warnings. – chux - Reinstate Monica Mar 12 '21 at 04:45

0 Answers0