Help Please !!!!!!!!

This is a discussion on Help Please !!!!!!!! within the C++ Programming forums, part of the General Programming Boards category; I am on the second part of the Tutorial on cpprogramming.com and i tried the age program Code: #include <iostream.h> ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    8

    Question Help Please !!!!!!!!



    I am on the second part of the Tutorial on cpprogramming.com
    and i tried the age program

    Code:
    #include <iostream.h>			
    			
    int main()				//Most important part of the program!
    {
      int age;				//Need a variable...
      
      cout<<"Please input your age: ";	//Asks for age
      cin>>age;				//The input is put in age
      
      if(age<100)				//If the age is less than 100
      {
         cout<<"You are pretty young!";     //Just to show it works
      }
      else if(age==100)		//I use else just to show an example 
      {
         cout<<"You are old";		//Just to show you it works...
      }
      else if(age>100)
      {
        cout<<"You are really old";	//Proof that it works for any condition
      }
      return 0;
    }


    I am using DEV-C++ Ver 4.9.9.1
    and when ever i compile and run , a command screen pops up but when i enter the age and press ENTER it exits HELP please

    nothing is working i even downloaded a chess game from one of the Threads but every time i try to run it , a black screen pops up and disappears really fast. HELP!!!!
    Last edited by xxghostsxx; 07-16-2005 at 01:02 PM.

  2. #2
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357
    it's not great programming using system, but can be useful when your starting out:
    system ( "pause" ) ;
    before you return, this runs "pause" through cmd.exe

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    8
    i didnt really understand what you just said i am Newbie so you going to have to speak in details.thanks

    OK NM i will try

  4. #4
    Registered User
    Join Date
    Jul 2005
    Posts
    8
    Quote Originally Posted by valis
    it's not great programming using system, but can be useful when your starting out:
    system ( "pause" ) ;
    before you return, this runs "pause" through cmd.exe

    THANK YOU SO MUCH YOU JUST MADE MY DAY



    COOLLLLLLLLL
    Now i can continue the TUTORIAL. thanks again

  5. #5
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,788
    You're program is working just fine, it's just that it displays its output and then exits so fast that you don't get a chance to read anything. Using system("pause") might work but a better alternative would probably be to put:

    Code:
    cin.get();
    right before the return statement.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  6. #6
    Registered User
    Join Date
    Jul 2005
    Posts
    8
    Quote Originally Posted by hk_mp5kpdw
    You're program is working just fine, it's just that it displays its output and then exits so fast that you don't get a chance to read anything. Using system("pause") might work but a better alternative would probably be to put:

    Code:
    cin.get();
    right before the return statement.
    Thanks i was about the ask for help again

  7. #7
    Registered User
    Join Date
    Jul 2005
    Posts
    8
    Code:
    #include <iostream.h>
    
    int mult(int x, int y);
    
    int main()
    {
      int x, y;
      cout<<"Please input two numbers to be multiplied: ";
      cin>>x>>y;
      cout<<"The product of your two numbers is "<<mult(x, y);
      return 0;
    }
    
    int mult(int x, int y)
    {
      cin.get();
      return x*y;
    }
    Okay how do i work that program i tried typing a # then Pressing ENTER then typing another one then ENTER again < after that it just exits

  8. #8
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Here is my answer to the multiplication program:

    Code:
    #include <iostream> //use iostream not iostream.h
    using namespace std;//include this so you will be able to use cout not std::cout
    
    int main()
    {
      int num1,num2,answer;
     
      
      cout<<"Please input a number to be multiplied: " << endl;
      cin>>num1;
      cout << "Please input a second number to be multiplied:" << endl;
      cin >>num2;
      answer=num1*num2;
      cout<<"The product of your two numbers is " << answer << endl;
      system("PAUSE");
      cin.get();
      return 0;
    }
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  9. #9
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    Quote Originally Posted by xxghostsxx
    Code:
    #include <iostream.h>
    
    int mult(int x, int y);
    
    int main()
    {
      int x, y;
      cout<<"Please input two numbers to be multiplied: ";
      cin>>x>>y;
      cout<<"The product of your two numbers is "<<mult(x, y);
      return 0;
    }
    
    int mult(int x, int y)
    {
      cin.get();
      return x*y;
    }
    Okay how do i work that program i tried typing a # then Pressing ENTER then typing another one then ENTER again < after that it just exits

    the cin.get() is in the wrong place.. its suppose to be in the main function...
    and put cin.ignore() after it..

  10. #10
    Registered User
    Join Date
    Jul 2005
    Posts
    8
    Quote Originally Posted by Sentral
    Here is my answer to the multiplication program:

    Code:
    #include <iostream> //use iostream not iostream.h
    using namespace std;//include this so you will be able to use cout not std::cout
    
    int main()
    {
      int num1,num2,answer;
     
      
      cout<<"Please input a number to be multiplied: " << endl;
      cin>>num1;
      cout << "Please input a second number to be multiplied:" << endl;
      cin >>num2;
      answer=num1*num2;
      cout<<"The product of your two numbers is " << answer << endl;
      system("PAUSE");
      cin.get();
      return 0;
    }

    Yours seem to work thanks
    and i also made a Division version of that one .
    ^ i know its not that impressing but hey i started reading that tutorial today i didnt Know nothing about c++ before and i am only 15 years old and i am trying to absorb everything that is tought in that tutorial . THANKS again for all your help.
    Last edited by xxghostsxx; 07-16-2005 at 03:08 PM.

  11. #11
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    Quote Originally Posted by xxghostsxx
    Yours seem to work thanks
    if you are going to be using system("PAUSE"); no need for cin.get()..

  12. #12
    Registered User
    Join Date
    Jul 2005
    Posts
    8
    Quote Originally Posted by mrafcho001
    if you are going to be using system("PAUSE"); no need for cin.get()..
    It worked both ways but i understand that it is not needed

  13. #13
    Registered User
    Join Date
    Jul 2005
    Posts
    8

    Question

    Code:
    struct database
    {
      int id_number;
      int age;
      float salary;
    };
    
    int main()
    {
      database employee;  //There is now an employee variable that has modifiable 
    			    //variables inside it.
      employee.age=22;
      employee.id_number=1;
      employee.salary=12000.21;    
      return 0;
    }
    I need help again its show up and disappearing right away.
    I tried using system("pause");AND ther other one. but its given me an error. "SYSTEM" UNDECLARED

    HELP

  14. #14
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    Quote Originally Posted by xxghostsxx
    Code:
    struct database
    {
      int id_number;
      int age;
      float salary;
    };
    
    int main()
    {
      database employee;  //There is now an employee variable that has modifiable 
    			    //variables inside it.
      employee.age=22;
      employee.id_number=1;
      employee.salary=12000.21;    
      return 0;
    }
    I need help again its show up and disappearing right away.
    I tried using system("pause");AND ther other one. but its given me an error. "SYSTEM" UNDECLARED

    HELP

    #include <iostream>
    using namspace std;

  15. #15
    *this
    Join Date
    Mar 2005
    Posts
    498
    the cin.get() is in the wrong place.. its suppose to be in the main function...
    and put cin.ignore() after it..
    cin.ignore(); then cin.get();

    First clear the stream.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

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