Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 27th, 2007, 12:54 AM   #1
ChevyCowboy15
Newbie
 
ChevyCowboy15's Avatar
 
Join Date: Nov 2007
Location: Central USA
Posts: 19
Rep Power: 0 ChevyCowboy15 is on a distinguished road
Talking Beginning Programming

i was just messing around with this because its my first program by myself but i am running into a problem here is my code:
// just messing around

#include <iostream>
using namespace std;

main ()
{
     //  X is the input of a question
     int x;
     // A is the correct answer to the question
     int a;
     // Declaring Year Variable which is this year
     int Year;
     // Year is this Year
     Year = 2007;
     // Declaring the answer to the question
     a = 2008;
     // saying what this year is
     cout << Year << endl;
     // asking the question
     cout << "What is the year next year?" << endl;
     // the action of the input
     cin >> x; 
         if (x == 2008);
            cout << "Your Right!" << endl;
         else
             cout << "NO!" << endl;
     
     
     cin.ignore(cin.rdbuf()->in_avail() + 1);
     
     return 0;
     
}
i am using Dev-C++ to write and complie this code and it comes up with this error

In function `int main()':
expected primary-expression before "else"
`;' before "else"

and i dont understand what is the problem coud someone help me... this program dont amount to anything i am just trying to learn how to program with this thanks

Last edited by DaWei; Nov 27th, 2007 at 1:38 AM. Reason: Added code tags. Read the rules.
ChevyCowboy15 is offline   Reply With Quote
Old Nov 27th, 2007, 1:08 AM   #2
titaniumdecoy
Programming Guru
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 1,007
Rep Power: 5 titaniumdecoy will become famous soon enough
Send a message via AIM to titaniumdecoy
Re: Beginning Programming

Use code tags next time you post.

There is a semicolon after the if statement that shouldn't be there: if (x == 2008);
titaniumdecoy is online now   Reply With Quote
Old Nov 27th, 2007, 1:17 AM   #3
ChevyCowboy15
Newbie
 
ChevyCowboy15's Avatar
 
Join Date: Nov 2007
Location: Central USA
Posts: 19
Rep Power: 0 ChevyCowboy15 is on a distinguished road
Re: Beginning Programming

Thank you for the help.. lol i forgot about that semicolon

and what code tags?
ChevyCowboy15 is offline   Reply With Quote
Old Nov 27th, 2007, 1:46 AM   #4
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 773
Rep Power: 3 Jimbo is on a distinguished road
Re: Beginning Programming

If you put [code] before your code segment, and [/code] after it when you post, it will preserve the formatting (i.e. indentation) of your code:
#include <iostream>
using std::cout;
using std::endl;

int main()
{
        cout << "hello world"
             << endl;
}
(it would have done the same for the "before your code segment, and" I wrote above, but there's another tag that stops it from doing that)
__________________
<insert disclaimer here>
<insert shameless plug for Visual Studio here>
Jimbo is offline   Reply With Quote
Old Nov 27th, 2007, 3:00 AM   #5
WaltP
Programmer
 
Join Date: Oct 2007
Posts: 39
Rep Power: 0 WaltP is on a distinguished road
Re: Beginning Programming

The first post in the forum Read Me: How to post a question explains the how to post good questions, including CODE tags. Might be worth a read...
WaltP is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming text book suggestions nisim777 Coder's Corner Lounge 7 Aug 19th, 2007 9:49 PM
Programming without post secondary education Eric the Red Other Programming Languages 6 Mar 7th, 2006 6:56 PM
Does Programming Make You Smarter? Sane Coder's Corner Lounge 43 Oct 2nd, 2005 7:12 AM
MIT's Metaphor For Software Programming Infinite Recursion Other Programming Languages 2 Jun 12th, 2005 7:42 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:31 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC