473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How to Terminate a program with invalid input.

Hello,

I was wondering how to stop a program if invalid input is used. I am working on a problem about ultimate frisbee teams. The input I ask for is how many wins they have. They only play 10 games and I need to stop the program if someone puts a value more than 10 as input. How would I do this?
Feb 10 '11 #1

✓ answered by horace1

something like
Expand|Select|Wrap|Line Numbers
  1. int main() {
  2.   int games;
  3.   scanf("%d",&games);
  4.   if(games>10) 
  5.     { printf("too many games! "); return -1; }
  6.  
return 0 from main() is the normal all OK return anything else is error

4 9447
Banfa
9,065 Expert Mod 8TB
Just return from main or if you are too deeply nested call exit or abort.
Feb 10 '11 #2
The input is right at the beginning of the code. How exactly do I return from main?
Feb 10 '11 #3
horace1
1,510 Expert 1GB
something like
Expand|Select|Wrap|Line Numbers
  1. int main() {
  2.   int games;
  3.   scanf("%d",&games);
  4.   if(games>10) 
  5.     { printf("too many games! "); return -1; }
  6.  
return 0 from main() is the normal all OK return anything else is error
Feb 10 '11 #4
Thank you so much!
Feb 10 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Al Wilkerson | last post by:
Quick question, does exceptions in Java by default terminate the main program? Thanks, -- Al
10
by: jeff regoord | last post by:
A user inputs a float value. The scanf() function gets the value. However, I need to create an error handler with an if else statement saying invalid input if the input is not a number. Does...
3
by: Andy Fish | last post by:
Hi, I have a RegularExpressionValidator with the following regexp ^{0,3}$ It mostly works, but allows a value consisting only of spaces to pass right through. Leading and trailing spaces...
3
by: mike | last post by:
I have the following view definition Column | Type | Modifiers ----------------+-----------------------+----------- bcode | character varying(15) | subhead ...
7
by: =?Utf-8?B?SmVycnk=?= | last post by:
Using VB express, I have a textbox in a form and want to ask the user to input a number , If the number is 114, then I want to do a form2.show /me.hide so the form2 comes up, but if they put in the...
3
vman595
by: vman595 | last post by:
Hey guys, does anyone know of a command in java that will close down the entire program? Thanks
7
by: Thana1995 | last post by:
Write a program that asks the user to give a two-character password(defined by constants within the program). the program should then test the validity of the password. if it is incorrect after three...
3
by: ALKASER266 | last post by:
Hey guyz I am a java beginner and I have problem with part of the code. The thing that I don't know how to do it in this code is how to show the user that he/she has input an invalid input In my...
1
by: 1251ila | last post by:
I am trying to import a text file into a postgres table and I get the following error message: Invalid input syntax for type date: field name The date format is yyyy-mm-dd So the text file...
1
by: chungku | last post by:
my frogram for it #!usr/local/bin/perl #program practice $file='input.txt'; open(FH, $file); @line=<FH>; open(OUT, ">>output.txt"); foreach $file(@line) {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.