473,320 Members | 1,820 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,320 software developers and data experts.

how do i make an if statement repeat itself in c?

im a beginner and i have to write a program that makes a guessing game. For example this should be my output.

How many games would you like to play JW? (1 – 10): 22
That’s too many!
How many games would you like to play JW? (1 – 10): 2

Lets Play game 1 JW

now the code that i wrote is

printf("\nHow many games would you like to play %c%c?(1-10)\n",firsti, secondi);
scanf("%d", &games);
if(games>1&&games<10)

printf("Lets play game 1\n");

else

printf("That's too many!\n");

what do i do so that the program goes back to the line "How many games would you like to play?"
Oct 10 '09 #1
2 10666
Banfa
9,065 Expert Mod 8TB
You need to use a loop one of

Expand|Select|Wrap|Line Numbers
  1. for(expresion1; expresion2; expresion3)
  2. {
  3.     /* Code to repeat */
  4. }
  5.  
  6. while(expression)
  7. {
  8.     /* Code to repeat */
  9. }
  10.  
  11. do
  12. {
  13.     /* Code to repeat */
  14. }
  15. while(expression);
  16.  
I sugest you look them up in your C/C++ reference books.
Oct 10 '09 #2
Markus
6,050 Expert 4TB
The do-while loop would my first choice here.

The code is pretty simple, so I'll chuck it to you in pseudo-form.

Expand|Select|Wrap|Line Numbers
  1. do
  2.   print your message (input number)
  3.   read number
  4.   if number breaks some rule
  5.     print some error
  6. while number breaks some rule
  7.  
I prefer the do-while because you always need that first message output and number read.

Hope this helps,
Mark (not a C expert).
Oct 10 '09 #3

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

Similar topics

15
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
35
by: Thierry Loiseau | last post by:
Hello all, and Happy end year 2005 ! Well, I would like to obtain a list of all JavaScript var statement, With "for...in" perharps ? That is bellow my recent test here, but the problem is...
37
by: Steven Bethard | last post by:
The PEP below should be mostly self explanatory. I'll try to keep the most updated versions available at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
18
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
28
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions!...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
1
by: Krij | last post by:
Hi! I've found the problem in my database (ms access 2000). The ting is that returning two or more orderlines requieres that both item has the same ItemID. When returning two different itemID,...
5
by: John L. Whelan | last post by:
Hi Everyone: I know that I can repeat a single character using the StrDup function. Is there a function that will allow me to repeat a string? StrDup(5,"John") returns "JJJJJ." Is there a...
2
XedinUnknown
by: XedinUnknown | last post by:
Hi! I am new to this forum, but not new to web design and programming. Nevertheless, I have never tried to use PNG so extensively in my pages. here's the problem. First, I have found that the...
7
by: cabman | last post by:
I'm having trouble with a page and getting the background image to repeat itself on the y-axis. Here is a sample of the code: div.main { background-image: url(backround_image.gif);...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.