Thread: problem declaring i

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    96

    problem declaring i

    Hi,

    I am having problem with my program, I have made a small program of a class where I have used "for loop" and I wanted to use an integer "i" in this program . The user inputs value which is stored in "i" and then the value stored in "i" is used in a function.

    My program is as follows:

    Code:
    #include<iostream>
    
    
    Class "Student"
    
    {
    
    public:
    
    getName();
    getAddress();
    getRollNumber();
    
    
    private:
    
    char Name;
    char Address;
    char RollNumber;
    
    
    };
    
    
    
    main()
    
    {
    
    
    
    for ( i=0; i<5; i++)
    
    {
    cout<<" Pls enter the name";
    
    cin >>i.Name;
    
    if(i!=char)
    
    {
    cout<<"Pls enter the name in character"
    
    }
    else
    ------------------------------------------------------

    I haven't continued this program but I wanted to know that how can I use the character input by user to store it in "i" and then use that "i" in the getName ,or getAddress function?

    How can I declare "i" before using it?

    I hope my question is clear


    Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > Class "Student"
    Maybe read last week's answer again.
    Question about Classes and Structure
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Start by fixing all syntax errors and give functions proper return values. While you're at it, make the program compilable.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    96
    Sorry for the mistake,

    I have declared these functions as:



    Code:
    #include<iostream>
    Code:
      
      
    class "student"
      
    { 
      
    public: 
      
    void getName(); 
    void getAddress(); 
    void getRollNumber(); 
         setRollNumber();    
      
    private: 
      
    char Name; 
    char Address; 
    char RollNumber; 
      
      
    }; 
      
      
      
    main() 
      
    { 
      
      
      
    for ( i=0; i<5; i++) 
      
    { 
    cout<<" Pls enter the name"; 
      
    cin >>i.Name; 
      
    if(i!=char) 
      
    { 
    cout<<"Pls enter the name in character"
      
    } 
    else
    
    

    --------------------------------------------------------

    I have made this mistake in typing,so how can I declare the "i" as a variable?


  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    This code will still not compile.
    I suppose you want "i" as a student. In such case, then "student i;" is sufficient, if you've actually made your program compilable.
    And I have already told you not to use char. Use std::string!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Oh no, we have another "1 million monkeys with 1 million typewriters" kind of programmer.
    Stop programming by guessing. You will not get anywhere that way!

    You also don't sem to pay any attention to the corrections that you've already been given.
    Go and read that other thread Salem linked to, and don't come back until you've fixed what twomers pointed out.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem in declaring dyanamic arrays in c
    By aqeel in forum C Programming
    Replies: 2
    Last Post: 09-23-2009, 12:10 AM
  2. Declaring struct problem
    By _DrMario_ in forum C Programming
    Replies: 2
    Last Post: 12-04-2006, 10:02 AM
  3. Problem declaring large arrays
    By mattAU in forum C Programming
    Replies: 5
    Last Post: 09-28-2006, 05:47 AM
  4. declaring a large array problem !
    By Array_Troubled in forum C++ Programming
    Replies: 10
    Last Post: 01-08-2003, 06:02 AM
  5. Problem declaring struct in allegro
    By bobish in forum Game Programming
    Replies: 7
    Last Post: 03-08-2002, 09:26 AM