loop that will keep looping only if numbers or + is entered

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 509 Views - Last Post: 23 September 2011 - 07:28 AM Rate Topic: -----

#1 assert(C)  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 71
  • Joined: 20-July 11

loop that will keep looping only if numbers or + is entered

Posted 23 September 2011 - 03:03 AM

Hello,


I need to a make a function in C which will keep looping onlt if the input is numbers or + I want the input to be numbers cause I want to do something with them. Please help


Regards,

This is IN C
Is This A Good Question/Topic? 0
  • +

Replies To: loop that will keep looping only if numbers or + is entered

#2 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 195
  • View blog
  • Posts: 1,619
  • Joined: 13-March 10

Re: loop that will keep looping only if numbers or + is entered

Posted 23 September 2011 - 03:27 AM

Well, there is a isdigit() function but it will only return true if input is 0, 1, 2,3,4,5,6,7,8 or 9. Otherwise false. But you can play with it and find out more.
Was This Post Helpful? 0
  • +
  • -

#3 assert(C)  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 71
  • Joined: 20-July 11

Re: loop that will keep looping only if numbers or + is entered

Posted 23 September 2011 - 03:44 AM

Please Help Not sure what to do I have tried manythings but I cant seem to work it out
Was This Post Helpful? 0
  • +
  • -

#4 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 195
  • View blog
  • Posts: 1,619
  • Joined: 13-March 10

Re: loop that will keep looping only if numbers or + is entered

Posted 23 September 2011 - 04:02 AM

I have this example in C++. However i am not testing whether its a number cuz im assuming the user will input the number.

Spoiler

This post has been edited by darek9576: 23 September 2011 - 04:09 AM

Was This Post Helpful? 0
  • +
  • -

#5 assert(C)  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 71
  • Joined: 20-July 11

Re: loop that will keep looping only if numbers or + is entered

Posted 23 September 2011 - 04:10 AM

but I want to still loop even if + is entered so it should loop still.
Was This Post Helpful? 0
  • +
  • -

#6 Ghost344  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 02-September 11

Re: loop that will keep looping only if numbers or + is entered

Posted 23 September 2011 - 04:12 AM

So basically the programs has to DO the input WHILE the input EQUALS a digit OR a plus sign? :)
Was This Post Helpful? 0
  • +
  • -

#7 assert(C)  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 71
  • Joined: 20-July 11

Re: loop that will keep looping only if numbers or + is entered

Posted 23 September 2011 - 04:14 AM

Yes Yes Yes Yes Yes but how do it I have tried many things HELP HELP HELP

BUT YES THATS WHAT IT HAS TO DO
Was This Post Helpful? 0
  • +
  • -

#8 assert(C)  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 71
  • Joined: 20-July 11

Re: loop that will keep looping only if numbers or + is entered

Posted 23 September 2011 - 04:31 AM

Please help
Was This Post Helpful? 0
  • +
  • -

#9 Ghost344  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 02-September 11

Re: loop that will keep looping only if numbers or + is entered

Posted 23 September 2011 - 04:34 AM

You could post all the methods you tried so far, could save some time.
Was This Post Helpful? 0
  • +
  • -

#10 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 195
  • View blog
  • Posts: 1,619
  • Joined: 13-March 10

Re: loop that will keep looping only if numbers or + is entered

Posted 23 September 2011 - 04:44 AM

This does not store anywhere your entries but you could use a vector for it however, i dont know vectors so you need to look it up and it stops also when user presses +. Add an OR clause at the end of the loop.
Good luck.
Spoiler

This post has been edited by darek9576: 23 September 2011 - 04:47 AM

Was This Post Helpful? 0
  • +
  • -

#11 assert(C)  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 71
  • Joined: 20-July 11

Re: loop that will keep looping only if numbers or + is entered

Posted 23 September 2011 - 04:49 AM

NO NO it should continue to loop even when a plus sign is added or digit anything else it should stop. What I did was I talk the input as string and decalred flag then if strcmp(input,"+") is true flag is ture and if number then true but does not work. I have tried many ways. I just want to basically loop if a number or plus sign is entered.

P.S. EVERYONE THANKS ALOT FOR YOUR HELP I THINK I AM NEARLY THERE
Was This Post Helpful? 0
  • +
  • -

#12 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 603
  • View blog
  • Posts: 1,864
  • Joined: 02-August 09

Re: loop that will keep looping only if numbers or + is entered

Posted 23 September 2011 - 04:49 AM

The answer I gave in your other thread is pretty much all you need. Just put the code in a while loop and add some sort of boolean flag which can be used as the condition for your loop. It's very trivial to expand the code to do that.
Was This Post Helpful? 0
  • +
  • -

#13 assert(C)  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 71
  • Joined: 20-July 11

Re: loop that will keep looping only if numbers or + is entered

Posted 23 September 2011 - 04:55 AM

But man I think aphex19 correct me if I am wrong you are taking one signle input from user like for example 12+1212121231 which correct but I want to scanf values in a loop and then check them. If they contain a number or plus sign if they do the loop continues else loop is terminated.
Was This Post Helpful? 0
  • +
  • -

#14 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 195
  • View blog
  • Posts: 1,619
  • Joined: 13-March 10

Re: loop that will keep looping only if numbers or + is entered

Posted 23 September 2011 - 05:14 AM

View Postassert©, on 23 September 2011 - 04:49 AM, said:

NO NO it should continue to loop even when a plus sign is added or digit anything else it should stop. What I did was I talk the input as string and decalred flag then if strcmp(input,"+") is true flag is ture and if number then true but does not work. I have tried many ways. I just want to basically loop if a number or plus sign is entered.

P.S. EVERYONE THANKS ALOT FOR YOUR HELP I THINK I AM NEARLY THERE


I know it should loop when + is entered and thats what i said in my post. Add one condition in my code and you are done. THen show us what you have produced.
Was This Post Helpful? 0
  • +
  • -

#15 assert(C)  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 71
  • Joined: 20-July 11

Re: loop that will keep looping only if numbers or + is entered

Posted 23 September 2011 - 05:27 AM

I had to learnt C++ to try your code okay got it working for c++ but I need the same concept in C here is the code in C++ thanks man


[code]
int main()
{

char input;



do{
cout << "Type in something" << endl;
cin >> input;
cout << input << endl;

}while( isdigit(input) !! input=='+');

cout << "Finishing the program" << endl;



cin.ignore();
cin.get();

return 0;
}


Thanks works the only thing left is translating in C and also converting the character if number into a number
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2