Sythe.Org Forums     Register     FAQ     Members List     Calendar     Mark Forums Read    
 
Sythe.Org Forums  
   Runescape Gold

Sythe.org — A Virtual Goods Trading Hub

Make real cash! buying and selling in-game items.

We have a no-scam policy.

You can make thousands playing your favourite games here at Sythe.org.

Just sign up an account and follow the rules!


Take me to

Runescape Markets

Other Game Markets

Support Center

Register an Account

Close
Novice C++ question
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 09-24-2011, 09:26 PM
distracted's Avatar
Active Member
 
Join Date: Jun 2009
Posts: 127
Default Novice C++ question

I began reading a PDF version of C++ Primer-Fourth Edition and am stuck on an exercise.

1) Write a program to print the larger of two inputs supplied by
the user.

This is what I have so far. Please clarify what I am doing wrong; don't simply post the correct code.

Code:
 #include <iostream>

using namespace std;

int main()
{
    int x, y;
    cout << "Enter two numbers to determine which one is greater";
    cin >> x >> y;

    if (x > y)
{

        cout << x "is the greater variable" ;
}
    else
    {


    cout << y "is the greater variable" ;
    }
    return 0;

}

Thanks.
Reply With Quote
  #2  
Old 09-24-2011, 09:30 PM
Guru
 
Join Date: Jun 2005
Location: Canada
Posts: 1,844
Default Re: Novice C++ question

With c++ (and other languages) for each variable/string you want to output, you must have a concatenation operator between them.

With c++ it's "<<" for outputs. With PHP it's ".", with C# it's "+".

Your code is correct, just the line which outputs the text has one small error.

Code:
if (x > y)
{
    cout << x << "is the greater variable" ;
}
else
{
    cout << y << "is the greater variable" ;
}
I've bolded and underlined the code which would fix it.
__________________


Last edited by blindkilla : 09-24-2011 at 09:31 PM.
Reply With Quote
  #3  
Old 09-25-2011, 07:02 AM
spots13's Avatar
Active Member
$5 USD Donor New
 
Join Date: Feb 2008
Location: Colombia
Posts: 213
Send a message via MSN to spots13
Default Re: Novice C++ question

totally correct blinkilla, btw if you wanna check my c++ guide and tell me what you think of it would be gr8 will be updating it soon again

Last edited by spots13 : 09-25-2011 at 07:03 AM.
Reply With Quote
  #4  
Old 09-25-2011, 09:28 AM
distracted's Avatar
Active Member
 
Join Date: Jun 2009
Posts: 127
Default Re: Novice C++ question

Thanks. I thought my mistake was a bug as opposed to a syntax error.
Reply With Quote
Reply



Cheap RS Gold Store  Runescape Gold

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT +1. The time now is 11:29 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.6.1