Hi!
i am writing a program in C that is a reservation maker. it supposed to ask if you wanna get first class or business class, and rest i have to finish. seats 1-5 are for first class, and seats 6-10 are for economy class. the probelm is that when seats 1-5 are full its supposed to ask if you wanna get a seat in economy and vice-versa. but everytime i get to seat 5 i get the error:
Airline has exited due to signal 11 (SIGSEGV).
can anyone help?? inew to C but not programming. THANKS
here is the functions class: - #include <stdio.h>
-
-
void arrayInitializer (int array[], int sizeArray){
-
int i;
-
for(i = 0; i < sizeArray; i++){
-
array[i] = 0;
-
}
-
}
-
-
void menuChoose (int type, int seatArray[]){
-
int theClass;
-
int i;
-
if(type == 1){
-
for(i = 0; i < 5; i++){
-
theClass = 1;
-
if(seatArray[i] == 1) {
-
if(i == 4 || (seatArray[0] == 1 && seatArray[1] == 1 && seatArray[2] == 1 && seatArray[3] == 1 && seatArray[4] == 1)) askOther(theClass, seatArray);
-
else continue;
-
}
-
else if(seatArray[i] == 0){
-
seatArray[i] = 1;
-
printTicket(i, theClass);
-
break;
-
}
-
}
-
}
-
else if(type == 2){
-
for(i = 5; i < 10; i++){
-
if(seatArray[i] == 1) continue;
-
else if(seatArray[i] == 0){
-
seatArray[i] = 1;
-
theClass = 2;
-
printTicket(i, theClass);
-
break;
-
}
-
else askOther(theClass, seatArray);
-
}
-
}
-
else printf("Hello!");
-
}
-
-
void printTicket(int seat, int theClass){
-
if(theClass == 1) printf("Boarding Pass: You Are In First Class And Your Seat Number is %d \n Enjoy your Flight!\n", seat);
-
else printf("Boarding Pass: You Are In Economy Class And Your Seat Number is %d \n Enjoy your Flight!\n", seat);
-
}
-
-
void askOther(int theClass, int seatArray[]){
-
char choice;
-
if(theClass == 1){
-
printf("First Class Is Full, Would You Like To Be Placed In Economy Class? (yes = y, no = n) ");
-
scanf("%c", choice);
-
if(choice == 'n') printf("Next Flight Leaves In Three Hours, Sorry");
-
if(choice == 'y') menuChoose( 2, seatArray);
-
else printf("Im Sorry, That Was Not A Valid Choice");
-
}
-
if(theClass == 2){
-
printf("Economy Class Is Full, Would You Like To Be Placed In First Class? (yes = y, no = n) ");
-
scanf("%c", choice);
-
if(choice == 'n') printf("Next Flight Leaves In Three Hours, Sorry");
-
if(choice == 'y') menuChoose( 1, seatArray);
-
else printf("Im Sorry, That Was Not A Valid Choice");
-
}
-
}
-
here is the driver class - #include <stdio.h>
-
#include "Driver.h"
-
-
int main(){
-
-
int decision, *decisionPtr;
-
decisionPtr = &decision;
-
int replay = 0;
-
int seatArray[10] = { 0 };
-
-
-
printf("Welcome To The Automated Reservation System\n");
-
while(replay == 0){
-
printf(" Please type ""1"" for First Class \n Please type ""2"" for Economy Class \n Please type ""3"" to cancel a reservation \n");
-
scanf("%d", decisionPtr);
-
menuChoose(*decisionPtr, seatArray);
-
}
-
return 0;
-
-
}
-
thanks guys!
0 1722 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Martin McCormick |
last post by:
A C program contains several signal statements to remove a
lock file if the program gets killed:
/*Set up interrupt handler to catch ctrl-C so that lock file can be removed.*/
signal(SIGINT,crash);
signal(SIGBUS,crash);
signal(SIGSEGV,crash);
This part works. Those signals cause the "crash.c" module to
run and get rid of the lock. Is there a standard way to also print
|
by: Seo Jae Ick |
last post by:
Hi? My name is Seo Jae Ick.
I have a problem with running a program on Linux RedHat 8.0.
GDB have reported this,
program exited with code 0377
I think, this statement comes when
1) explicit call in process exit(-1) <- 0377(octet) = -1(decimal)
|
by: Jackie |
last post by:
Hi everyone,
I'd like to know when and how signals are used (e.g. SIGFPE, SIGABRT,
SIGTERM, SIGSEGV, SIGINT)? Thank you so much.
|
by: Sontu |
last post by:
Hi all,
Consider the following code:
#include<signal.h>
#include<stdio.h>
#include<sys/mman.h>
void handler(int sig)
{
|
by: vashwath |
last post by:
Hi all,
In my current project I am using signals for error handling. Since I
cannot show full code, I have just shown important piece of code which
is relevant.
void sigsegenv()
{
printf("\n\n ********** F D S Message ***********\n\n");
printf("\n\n ********** S E G M E N T A T I O N F A U L T
inside F D S ***********\n\n");
| |
by: David Willoughby |
last post by:
I'm attempting to catch bugs in my program using signal.h with sigsegv.
now i know when i'm in gdb i can catch bugs but is there any variable
that stores like the file that caused the bug and possible calling
procs? or would that only be left to something with gdb.
|
by: subramanian |
last post by:
Consider the following code: segment violation is deliberately
generated to catch the SIGSEGV signal. The handler for this signal,
namely SIGSEGV_handler, is called. However after the handler is
finished, control does not return to the printf statement in main()
which is present after the strcpy statement. Instead Segmentation
violation error message is printed in Redhat Linux and the program is
aborted. In VC++, the SIGSEGV_handler is...
|
by: Leet Jon |
last post by:
Hi what's the reason for having the default disposition for SIGSEGV,
SIGFPE, SIGBUS etc to be terminating the program, when these signals can
just be ignored by the program? Many programs crash with SIGSEGV -
they'd be much less flakey if the default was to try to carry on.
~Jon~
|
by: Udai Kiran |
last post by:
Hi all
Iam having trouble with signal handler. Where will the execution
return after invoking a signal handler when that particular signal is
recieved? will return to the point where we register the signal?
The following code is recieveing recursive signals.
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |