Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey everyone.

I have a little problem here. Let me explain.

What I want to do is to get a decimal number(0 to 9) from user and do the work according to the number. After operation, The program should ask again what to do to user in an infinite manner.

I know this is an easy thing to do, but could'nt make it :/
How can I achieve this?

Any examples, definitions, codes will be appreciated :)
Posted
Comments
walterhevedeich 5-Aug-11 2:32am    
Infinite? But why?
Un_NaMeD 5-Aug-11 2:40am    
Hi sir.
What else can I do?
After any operation according to number user chose, the program exits.
if any other ideas to block the program from quiting, that will be well accepted :)
Albert Holguin 5-Aug-11 10:41am    
Why not? A lot of programs run in an infinite loop until the user chooses to terminate the application.
walterhevedeich 5-Aug-11 10:57am    
You're right. I probably missed the part where he mentioned that an option would be to terminate the application.
Sergey Alexandrovich Kryukov 5-Aug-11 2:49am    
Console application? If so, add a tag "Console application", don't puzzle people.
--SA

1 solution

Something like this,
C#
int nChoice;
while(1)
{
    printf("Choose a Number between 0 to 9(-1 to exit):"); //i just taken -1 to exit
    scanf("%d", &nChoice);
    if(nChoice == -1)
        break; //Break the loop;
    //else 
    //Do your work
}
 
Share this answer
 
Comments
Emilio Garavaglia 5-Aug-11 2:54am    
simple and to the point.
I voted 4 (not 5) since this is C, not C++.
Albert Holguin 5-Aug-11 10:40am    
that's exactly the way to do it... my 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900