Help with Code

This is a discussion on Help with Code within the C++ Programming forums, part of the General Programming Boards category; #include <iostream.h> // cin and cout are defined in this header void main() { double Input=0; // This will hold ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    11

    Help with Code

    #include <iostream.h> // cin and cout are defined in this header

    void main()
    {
    double Input=0; // This will hold keyboard input
    double Total=0; // This will hold the total

    // Type a welcome message
    cout<<"Welcome to the C++ Game Tutorials Adding Machine"
    <<endl;

    {
    cout<<Enter a number please. or else
    }

    //Loop till the user enters -666
    while(Input!=-666)
    {
    cout<<"Enter a value (-666 to exit): "; // Prompt user
    cin>>Input; // Take input
    Total = Total + Input; // Add total
    cout<<endl // Print total
    <<"Total = "<<Total<<endl;
    }

    cout<<"Good Bye!"<<endl<<endl;
    }


    1. Well I need a way to say that if 'Input' is not a number, it displays "This is not a number."

    2. Well when I compile for some programs, the screen usually just flashes and exits. is there a way to kind of pause the program for the viewer to clearly see the contents of the program.

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    94
    I can help with the second thing. However, for the second thing, you can use cin.get(), getch(), or system("pause")

    Brendan
    Draco dormiens nunquam titillandus

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    11
    thanx mr. porter
    www.solidgone.com

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    68

    Check if number is Digit

    Hi U,

    take an input form user and check if it is digit. Some thing like this. Hope this helps.

    Code:
      #include <iostream.h> // cin and cout are defined in this header 
      #include<ctype.h>
    
    void main() 
    { 
    double Input=0; // This will hold keyboard input 
    double Total=0; // This will hold the total 
    
    // Type a welcome message 
    cout<<"Welcome to the C++ Game Tutorials Adding Machine" 
    <<endl; 
    
    //Loop till the user enters -666 
    while(Input !=-666) 
    { 
    cout<<"Enter a value (-666 to exit): "; // Prompt user 
    cin>>Input; // Take input 
    if(isdigit(Input))//isxdigit() can check if it is hex and isdigit() will check for decimal and digit
    {
        Total = Total + Input; // Add total 
        cout<<endl<<"Total = "<<Total<<endl;  // Print total 
       cout<<"Please Enter Something To Exit"<<endl;
        cin.get()
    }
    else
    {
      cout<<"This is not a number." <<endl;
    }
    } 
    
    cout<<"Good Bye!"<<endl<<endl; 
    }

  5. #5
    Registered User
    Join Date
    Jul 2002
    Posts
    11
    thanx all
    www.solidgone.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

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