clueless

This is a discussion on clueless within the C++ Programming forums, part of the General Programming Boards category; 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 ...

  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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    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 11:56 AM.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



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

  4. #4
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    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)
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  5. #5
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,616
    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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    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.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  7. #7
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,616
    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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    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.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,413
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 08:52 AM

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