quick ? people

This is a discussion on quick ? people within the C++ Programming forums, part of the General Programming Boards category; aight im doing an exercise in a book and i want it to ask how many total points can the ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    255

    quick ? people

    aight im doing an exercise in a book and i want it to ask how many total points can the student earn which i can do that but i i want it to say like press 'q' to quite and obviously points are numbers and thats crossing variable types so is there a way i can make so i can still ask for a number and use it for a number while allowing a 'q' for input i tryed jus flat out using 'q' there but it jus repeated some output and did nuthin so can anyone help out real fast thanx bye
    hooch

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    take it easy take your time to write a post(if u want uss to do the same)

  3. #3
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    disclaimer: i have almost no idea what you mean.

    read everything in as a string, test for 'q' or 'Q', then convert to int or float and proceed

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    Input everything as a string, then decide how to convert it by looking at the chars typed in

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    139
    um two variables of int and char

    get the number
    ask if they want to do it again (y/n)
    get char
    repeat if y.

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    make a big loop

    use swich as after the () of the main
    int main() {
    cout inter the first char
    switch {char x of
    case 'c' : continure {
    youwrite here your progam

    }

    case' q': break;
    }// switch
    cout <<" Good by"
    }/main
    C++
    The best

  7. #7
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    oh so i ask seperately if they want to continue or not? i cant make it all one question?
    hooch

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    > oh so i ask seperately if they want to continue or not? i cant make it all one question?
    Of course you can

    Code:
    char answer[100];
    cin.getline( answer, sizeof(answer) );
    if ( isdigit( answer[0] ) {
      // convert answer to a number
    } else
    if ( answer[0] == 'y' ) {
      // yes
    } else
    if ( answer[0] == 'n' ) {
      // no
    }
    Or any variation on this theme which you care to imagine

  9. #9
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    hmm while that makes sense except i havent learned what the isdigit() does exactly my guess is it converts the numberal naswer to digits or gets the numeric value for strings?
    hooch

  10. #10
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Nope. Try putting a question mark after the function name for a clue.

  11. #11
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    aight heres what i got
    without the ? mark i have an error saying isdigit is an undeclared identifyer so is there a header that i need for this thing?

    i think im getting the hint for the isdigit so it would ask with a ? sumwhere which i cant figure out quite where to put since i keep getting errors and i dont understand them since ive never known what ? marks do in coding altho i have seen them but heres what i got

    i also tryed like 5 places for the ? mark jus to see what it did and i kept getting these 4 errors or errors similar to them in all cases



    #include <iostream.h>
    int main()
    {
    char answer[100];
    cin.getline( answer, sizeof(answer) );
    if ( isdigit?( answer[0] )) {
    // convert answer to a number
    } else
    if ( answer[0] == 'y' ) {
    cout<<"this is the yes slot"<<endl;
    // yes
    } else
    if ( answer[0] == 'n' ) {
    cout<<"this is the no slot"<<endl; // no
    }
    return 0;
    }



    --------------------Configuration: isdigit - Win32 Debug--------------------
    Compiling...
    isdigit.cpp
    C:\Windows\Desktop\c++\isdigit.cpp(6) : error C2065: 'isdigit' : undeclared identifier
    C:\Windows\Desktop\c++\isdigit.cpp(6) : error C2059: syntax error : ','
    C:\Windows\Desktop\c++\isdigit.cpp(6) : error C2143: syntax error : missing ';' before '{'
    C:\Windows\Desktop\c++\isdigit.cpp(8) : error C2181: illegal else without matching if
    Error executing cl.exe.

    isdigit.obj - 4 error(s), 0 warning(s)
    hooch

  12. #12
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187
    include the string header file or ctype for 'isdigit'

  13. #13
    Registered User
    Join Date
    Apr 2002
    Posts
    200
    I dont think Sorensen meant to literally put a '?' after isdigit() in your code. He meant it as a response to your question as to what is the purpose of isdigit(). Think about it a little. Or even better, use one of those bizarre things called 'search engines.' I've heard that the one called 'www.google.com' is pretty good. Kinda high-tech though. Alternatively, it is included in the functions section of this site.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick Sort Help
    By NavyBlue in forum C Programming
    Replies: 1
    Last Post: 03-02-2003, 09:34 PM
  2. I'm worried about some of the people wanting to program...
    By damonbrinkley in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 11-23-2002, 06:38 AM
  3. February 1, 2019...
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 98
    Last Post: 08-03-2002, 07:24 AM
  4. Replies: 0
    Last Post: 04-30-2002, 07:24 PM
  5. Language
    By nvoigt in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 04-29-2002, 02:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21