Like Tree1Likes
  • 1 Post By iMalc

problem declaring i

This is a discussion on problem declaring i within the C++ Programming forums, part of the General Programming Boards category; Hi, I am having problem with my program, I have made a small program of a class where I have ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,449
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,449
    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,295
    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.
    Elysia likes this.
    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, 09: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, 05:02 AM
  5. Problem declaring struct in allegro
    By bobish in forum Game Programming
    Replies: 7
    Last Post: 03-08-2002, 08:26 AM

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