whats wrong with this very simple code?

This is a discussion on whats wrong with this very simple code? within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> using namespace std; int main() { int val; cout<<"enter a number 1-10"; cin>> val; cin.ignore(); if ( ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    6

    whats wrong with this very simple code?

    Code:
    #include <iostream>
    using namespace std;
    int main()                           
    {
    	int val;
    	cout<<"enter a number 1-10";
    	cin>> val;
    	cin.ignore();
    	if ( val != 5 ) {
    		cout<<"wrong/n";
    	}
    	else {
    		cout<<"correct/n";
    	}
    	cin.get()
    }
    i get this error: error C2143: syntax error : missing ';' before '}'

    im using visual studio 2008 express.
    thanks guys.
    by the way, im coming from a visual basics background so bear with me! haha

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,630
    You forgot a terminating semi-colon on this line:
    Code:
    cin.get()
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    6
    Quote Originally Posted by laserlight View Post
    You forgot a terminating semi-colon on this line:
    Code:
    cin.get()
    woops, thanks! that worked haha.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with simple piece of code
    By Furious5k in forum C++ Programming
    Replies: 10
    Last Post: 12-12-2008, 04:25 PM
  2. What's wrong with this code?
    By Luciferek in forum C++ Programming
    Replies: 4
    Last Post: 06-21-2008, 12:02 PM
  3. Whats wrong with this simple code?
    By o14v in forum C++ Programming
    Replies: 4
    Last Post: 03-19-2008, 01:46 PM
  4. What is wrong with my code? My first program......
    By coreyt1111 in forum C++ Programming
    Replies: 11
    Last Post: 11-14-2006, 01:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21