I am using both Xcode(Mac book) and DEV C++.
One program is no problem in DEV C++, but some problem in Xcode.
As a command auto executed in Xcode only.
I simplified for this program to try to find what the problem is.
This program purpose is the calculation for booking the signal room or double room, staying for the number of nights and number of people lived.
[CODE]
#include <stdio.h>
int main() {
int number; /* How many people are booked the hotel. */
char room; /* Room type both D (double room) or S (single room) */
/* Read a number of people who needed to book the hotel. The number of peoples
are not accepted negative value */
room =0;
number =0;
while(1){
printf("Enter the number of people:");
scanf("%d", &number);
fflush(stdin);
if(number < 1){
printf("Input not correct\n");
continue;
}
break;
}
/* Verify the selection of room type both are 'D' or 'S',
The entry must be 'D' or 'C', otherwise, the program will be looped.*/
while(1){
printf("Enter the room type:");
scanf("%c", &room);
if(room != 'S' && room !='D'){
printf("You have entered a wrong room type!\n");
continue;
}
break;
}
return 0;
}
[/CODE]
Following is a full version :
Code:
#include <stdio.h>
int main() {
int nights; /* How many nights will be booked by each people or a pair. */
int number; /* How many people are booked the hotel. */
char room; /* Room type both D (double room) or S (single room) */
int nightsTotal; /* The total night will be booked that calculated by the amount
of people, type of room and how many nights will stay.*/
int rooms; /* The total of the room are needed */
/* Read a number of people who needed to book the hotel. The number of peoples
are not accepted negative value */
rooms =0;
rooms =0;
number =0;
while(1){
printf("Enter the number of people:");
scanf("%d", &number);
fflush(stdin);
if(number < 1){
printf("Input not correct\n");
continue;
}
break;
}
/* Verify the selection of room type both are 'D' or 'S',
The entry must be 'D' or 'C', otherwise, the program will be looped.*/
while(1){
printf("Enter the room type:");
scanf("%c", &room);
if(room != 'S' && room !='D'){
printf("You have entered a wrong room type!\n");
continue;
}
break;
}
/* Read the number of nights will be booked, at lease 1 night */
while(1){
printf("Enter the number of nights:");
scanf("%d", &nights);
fflush(stdin);
if(nights >=1)
break;
}
printf("Room booking received.");
fflush(stdin);
/* calculation of the nights are needed for a single room or double,
Single room is booked only for one people, but one people can be bookedthe double room, as some people who like living in a double room alone.*/
if (room == 'S'){
rooms =1 * number;
}
else if(room == 'D'&& number >2)
rooms = (number / 2)+(number % 2);
nightsTotal = nights * rooms;
/* printout the total night for all booked room; e.g.: 3 people live in double room
1 night, that will be displayed 2 nights.*/
printf("Room type %c for %d people for %d nights.", room, number, nightsTotal);
return 0;
}
thanks