![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2007
Location: Central USA
Posts: 19
Rep Power: 0
![]() |
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;
}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. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
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); |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Nov 2007
Location: Central USA
Posts: 19
Rep Power: 0
![]() |
Re: Beginning Programming
Thank you for the help.. lol i forgot about that semicolon
and what code tags? |
|
|
|
|
|
#4 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 773
Rep Power: 3
![]() |
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;
}
__________________
<insert disclaimer here> <insert shameless plug for Visual Studio here> |
|
|
|
|
|
#5 |
|
Programmer
Join Date: Oct 2007
Posts: 39
Rep Power: 0
![]() |
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...
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |