Why doesn't it work?

This is a discussion on Why doesn't it work? within the C++ Programming forums, part of the General Programming Boards category; Why doesn't the following code work? #include <iostream.h> int main() { int favnum; int nxt; cout<<"enter a number from 1-100"; ...

  1. #1
    pimping machinery
    Guest

    Question Why doesn't it work?

    Why doesn't the following code work?



    #include <iostream.h>
    int main()
    {
    int favnum;
    int nxt;
    cout<<"enter a number from 1-100";
    cin>>favnum;
    cout<<"you entered: "<<favnum
    cout<<"now type either a 1 or 2";
    cin>>nxt;
    if (nxt==1, nxt==2)
    {
    if (nxt==1)
    {
    cout<<"your number is 1";
    }
    else if (nxt==2)
    {
    cout<<"your number is 2";
    }
    else
    {
    cout<<"hey, you didn't type 1 or 2! meanie!!!!";
    }
    }

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    It just needed a little tweeking...
    Code:
    #include <iostream>
    using namespace std;
     
    int main() 
    { 
    	int favnum; 
    	int nxt; 
    
    	cout << "enter a number from 1-100: "; 
    	cin >> favnum; 
    	cout << "you entered: " << favnum << endl;
    	
    	cout << "now type either a 1 or 2"; 
    	cin >> nxt; 
    
    	if ( nxt == 1 ) 
    	{ 
    		cout << "your number is 1" << endl; 
    	} 
    	else if (nxt == 2 ) 
    	{ 
    		cout << "your number is 2" << endl; 
    	} 
    	else 
    	{ 
    		cout << "hey, you didn't type 1 or 2! meanie!!!!" << endl; 
    	} 
    
    	return 0;
    }
    I'll let you find the changes it will be a good exercise.

  3. #3
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    857
    One more:

    #include <iostream.h>
    int main()
    {
    int favnum;
    int nxt;
    cout<<"enter a number from 1-100";
    cin>>favnum;
    cout<<"you entered: "<< favnum;
    cout<<"now type either a 1 \or 2";
    cin>>nxt;
    if (nxt==1, nxt==2)
    {
    if (nxt==1)
    {
    cout<<"your number is 1";
    }
    else if (nxt==2)
    {
    cout<<"your number is 2";
    }
    else
    {
    cout<<"hey, you didn't type 1 or 2! meanie!!!!";
    }
    }

    Take a look at this
    Yoshi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM

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