Thread: clueless

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    4

    clueless

    Hi, I'v recently started self learning C++ but I'm already struggling.
    I'm presuming it's something stupid I'm doing. The error I keep getting is "1>loops.cpp(8): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int". ​I was reluctant to post this as such a new member and have tried the search function to no success so I'm sorry if I missed something blatant. Anyway, any help would be greatly appreciated.

    Code:
    // loops.cpp : main project file.
    
    #include "stdafx.h"
    #include "iostream"
    using namespace std;
    
    
    main()
    {
    	int loop;
    	int first = 1;
    	int second = 0;
    	int answer;
    	
    	cout << "-Fibonchi system-/n";
    	cout << "Please enter how many numbers you would like in the fibonchi system/n";
    	cin >> loop;
    	cout << "1 ";
    	while(loop>>1)
    	{
    		answer = first + second;
    		cout << answer <<" ";
    		loop = loop - 1;
    		second = first;
    		first = answer;
    	}
    	cout << endl;
    	system("pause");
    	return 0; 
    }

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    That is because main() must return int.
    Change
    Code:
    main()
    {
        //Everything else
    }
    to
    Code:
    int main()
    {
        //Everything else
        return 0;
    }
    Also
    1.Get rid of system("pause") and use cin.get();
    2.Change "iostream" to <iostream>
    3.Newline is '\n' ..not '/n'
    Other than that, the program seems okay.
    Last edited by manasij7479; 02-14-2012 at 12:56 PM.

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    Line #19, "while (loop>>1)" will surely not work the way you think.
    Devoted my life to programming...

  4. #4
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by GReaper View Post
    Line #19, "while (loop>>1)" will surely not work the way you think.
    But will work the same as "while(loop>1)" !(afaik)

  5. #5
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    10 >> 1 == 5 == true
    -10 >> 1 == -5 or something very large == true

    10 > 1 == true
    -10 > 1 == false

    Do they work the same?
    Devoted my life to programming...

  6. #6
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by GReaper View Post
    10 >> 1 == 5 == true
    -10 >> 1 == -5 or something very large == true

    10 > 1 == true
    -10 > 1 == false

    Do they work the same?
    For this program, they do.. as nothing negative is involved.

  7. #7
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    Quote Originally Posted by manasij7479 View Post
    For this program, they do.. as nothing negative is involved.
    Maybe, maybe not. What if the user is a psycho and inputs a negative number of a very large number.
    Devoted my life to programming...

  8. #8
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by GReaper View Post
    Maybe, maybe not. What if the user is a psycho and inputs a negative number of a very large number.
    The while loop does not get executed at all..and the program only prints "1"... which I'd say is quite reasonable && innocent.

  9. #9
    Registered User
    Join Date
    Feb 2012
    Posts
    4
    Thanks alot . Was following a tut and trying to work out what everything did, seems so obvious now you'v pointed it out but I'd never have figured it myself

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I believe shifting signed operands is implementation defined.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Shift right of negative integers is implementation defined (well it's also ID for positive signed integers as well, but the effect is moot for positives).
    >> may propagate the sign bit or a zero into the most significant bit of the result.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Clueless on an Assignment
    By PYROMANIAC702 in forum C Programming
    Replies: 12
    Last Post: 07-14-2011, 07:27 AM
  2. Completely Clueless!!
    By jap2010 in forum C++ Programming
    Replies: 13
    Last Post: 10-13-2009, 02:30 AM
  3. clueless
    By majornewb in forum C++ Programming
    Replies: 3
    Last Post: 12-11-2004, 09:52 AM