Thread: Making an Algorithm repeat itself

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by mvd1212
    scanf("%c", %choice);
    Quote Originally Posted by filker0
    scanf("%c", choice);
    Boy you guys are having a heckuva time with that one today...
    Code:
    char choice;
    ...
    scanf("%c", &choice );


    [edit]
    LMAO. I forgot the 'choice' in my smart ass reply and had to edit it in. But hey, I got the colored &. But in my defense, I have numerous alcoholic beverages as witnesses.
    [/edit]

    Quzah.
    Last edited by quzah; 12-02-2005 at 04:50 PM.
    Hope is the first step on the road to disappointment.

  2. #2
    Sr. Software Engineer filker0's Avatar
    Join Date
    Sep 2005
    Location
    West Virginia
    Posts
    235

    Oops.

    Quote Originally Posted by quzah
    Boy you guys are having a heckuva time with that one today...
    Code:
    char choice;
    ...
    scanf("%c", &choice );
    Oops... I cut/pasted his code sample, then when I saw the %, I went in and edited it out. Yes, you need the & for a %c. I had considered suggesting that he do a %s, make choice an array, and use
    Code:
    while (choice[0] == 'y');
    Typing as someone who's been coding in C since 1981 and has written more than one printf() implementation, I hang my head in shame at my omission.
    Insert obnoxious but pithy remark here

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    5
    hehe... Yeah I didn't make that same mistake in the code.

    I've tried to set choice = 'y' at the beginning of the code but it doesn't seem to do anything. I keep getting the problem that it'll print the message "Would you like to find another answer (y or n)? " and then it exits the code without waiting for input from the user.

    I'm sorry if I'm making this difficult, I'm pretty new at this and if the option came at the beginning of the code then I could do it easily.

    My instructor has just taught us about arrays and while she did say you could probably use them in this project, don't use them.

    I thought there was some simple method to get the code to loop back that I was missing. Is it more complex then I imagined?

    I'm not allowed to flush the input or use arrays. Not that I would know how to do that anyway.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  2. Database Search Algorithm
    By Krupux in forum C Programming
    Replies: 1
    Last Post: 08-28-2003, 09:57 PM
  3. Help with an algorithm
    By PJYelton in forum C++ Programming
    Replies: 15
    Last Post: 06-11-2003, 10:25 AM
  4. Replies: 2
    Last Post: 01-13-2003, 01:28 PM