Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-19-2012, 04:18 AM   PM User | #1
abrofunky
New to the CF scene

 
Join Date: Feb 2012
Posts: 6
Thanks: 2
Thanked 0 Times in 0 Posts
abrofunky is an unknown quantity at this point
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();

 }
abrofunky is offline   Reply With Quote
Old 02-19-2012, 05:25 AM   PM User | #2
Chocoholic_Jedi
New to the CF scene

 
Join Date: Feb 2012
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
Chocoholic_Jedi is an unknown quantity at this point
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.
Chocoholic_Jedi is offline   Reply With Quote
Users who have thanked Chocoholic_Jedi for this post:
abrofunky (02-21-2012)
Old 02-19-2012, 02:19 PM   PM User | #3
nojtb
New Coder

 
Join Date: Aug 2007
Posts: 59
Thanks: 3
Thanked 1 Time in 1 Post
nojtb is an unknown quantity at this point
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 10:33 PM..
nojtb is offline   Reply With Quote
Old 02-21-2012, 04:13 AM   PM User | #4
abrofunky
New to the CF scene

 
Join Date: Feb 2012
Posts: 6
Thanks: 2
Thanked 0 Times in 0 Posts
abrofunky is an unknown quantity at this point
thanks alot that really helped out. Peace
abrofunky is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:23 PM.


Advertisement
Log in to turn off these ads.