Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: using data

  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    using data

    This program execute but It is not coming how I wanted.

    for example I want name and grade to be in the column and row have what I had enter.


    name Grade
    J 54
    K 65

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
        struct student
    {
    
        string name;
        int grade;
    
    };
    
     int main()
     {
         student people1;
         student people2;
    
    
         cout << "Please enter student name: ";
         cin >> people1.name;
         cout <<" Pleae enter student grade: ";
         cin >> people1.grade;
    
         cout << "Please enter student name: ";
         cin >> people2.name;
         cout <<" Pleae enter student grade: ";
         cin >> people2.grade;
    
         cout << "Name" << "          " << "Grade" << endl;
    
       cout << " people1.name " << "        " << " people1.grade " << endl;
    
       cout << " people2.name " << "        " << " people2.grade " << endl;
    
         cin.get();
    
     }

  • #2
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post
    You don't want quotes around your calls to people1.name, people2.name, people1.grade and people2.grade in your print statements. That's why it's printing out "people1.name" "people1.grade", etc. instead of actually printing their name and grade. Just do
    Code:
    cout << people1.name;
    instead when you're accessing a value when printing.

  • Users who have thanked Chocoholic_Jedi for this post:

    abrofunky (02-21-2012)

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    59
    Thanks
    3
    Thanked 1 Time in 1 Post
    Escape seqences

    \a /*alert (bell)*/
    \b /*backspace*/
    \f /*formfeed*/
    \n /*newline*/
    \r /*carriage return*/
    \t /*horizontal tab*/
    \v /*vertical tab*/
    \\ /*backslash*/
    \? /*question mark*/
    \' /*single quote*/
    \" /*double quote*/
    \000 /*octal number*/
    \xhh /*hexadecimal number*/

    cout << "Name" << "\t" << "Grade" << endl;
    cout << people1.name << "\t" << people1.grade << endl;
    cout << people2.name << "\t" << people2.grade << endl;
    Last edited by nojtb; 02-19-2012 at 11:33 PM.

  • #4
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    thanks alot that really helped out. Peace


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •