would this work

This is a discussion on would this work within the C++ Programming forums, part of the General Programming Boards category; Well im sittin in class bored and i dont have a complier here so i went to the tutorials and ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    22

    would this work

    Well im sittin in class bored and i dont have a complier here so i went to the tutorials and i wrote a program similar to the age on in the tutorial but different do you see any errors in this????????????????????????????????????
    Code:
    // TimeSpent.cpp
    // by laughman
    
    #include <iostream
    
    int main()
    
    {
    
    	int time; //time on puter
    
    	cout << "Input the time you spend on computers daily: "; //question
    
    	cin >> time; //amount of time
    
    	if(time<4) //if statement
    
    	{
    
    	cout << "eh your the normal computer user!"; //answer output
    
    	}
    
    	else if(age>4) //if 2
    
    	{
    
    	cout << "Eh what are you up to you little scientist!\a\a\a\a\a"; //answer 2 output
    
    	}
    
    	return 0; //return to OS
    
    }

    also if i dont want it to return to the os what would i set the return as

    [edit]Tagged by Hammer
    Laugh

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    The include needs a closing >, you forgot namespaces completely, and there is no age variable. I assume you meant time.
    Code:
    #include <iostream>
    
    int main()
    {
      int time; //time on puter
    
      std::cout << "Input the time you spend on computers daily: "; //question
      std::cin >> time; //amount of time
    
      if(time<4) //if statement
      {
        std::cout << "eh your the normal computer user!"; //answer output
      }
      else if(time>4) //if 2
      {
        std::cout << "Eh what are you up to you little scientist!\a\a\a\a\a"; //answer 2 output
      }
    
      return 0; //return to OS
    }
    >also if i dont want it to return to the os what would i set the return as
    Calling return from main doesn't necessarily mean you will return to the operating system, it only means you will return to the calling process, what that process is may or may not be the system itself. To answer you question, you don't. You have no choice but to release control to the function that called your program when you say return in main.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    22
    do you have to have all the std's

    Code:
    #include <iostream>
    
    int main()
    {
      int time; //time on puter
    
      std::cout << "Input the time you spend on computers daily: "; //question
      std::cin >> time; //amount of time
    
      if(time<4) //if statement
      {
        std::cout << "eh your the normal computer user!"; //answer output
      }
      else if(time>4) //if 2
      {
        std::cout << "Eh what are you up to you little scientist!\a\a\a\a\a"; //answer 2 output
      }
    
      return 0; //return to OS
    }
    [edit]Tagged by Hammer.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    >do you have to have all the std's

    No, no and yes.

    You can write 'using namespace std;' below your includes which allows you to avoid the 'std::' prefix in the code.

    You can write 'using std::cout;', 'using std::cin;', etc. below the includes which also eliminates the need for using 'std::' in your code.

    Last, you can write the code as Prelude illustrated.

    The first option should be avoided as it's not good programming practice. The second has the limitation - if you want to call it that - of having to add every std::whatever in your list that occurs within your code. The last option, of course, entails a good deal of typing.

    Your call.

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happy about helping you


    For example:

    Without code tags:

    for(int i=0;i<5;i++)
    {
    cout << "No code tags are bad";
    }

    With Code Tags:
    Code:
    for(int i=0;i<5;i++)
    {
         cout << "This code is easy to read";
    }
    This is of course a basic example...more complicated code is even easier to read with code tags than without.

    I've added code tags for you this time. They can be added by putting [ code ] at the beginning of your code and [ /code ] at the end, only without the spaces. More information on code tags may be found at the link in my signature. Any further questions or ways I can help please feel free to PM me.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 08:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 11:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 11:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 05:36 PM

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