Thread: final exam in the morning

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    5

    Talking final exam in the morning

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
    	const int SIZE = 5;
    	int values[SIZE], counter, temp;
    	bool swap;
    
    	
    	for (counter=0; counter<SIZE; counter++)
    	{
    		cout<<"please input a number"<<endl;
    		cin>>values[counter];
    	}
    
    	do
    	{	swap = false;
    		for (counter=0; counter<values[counter-1]; counter++)
    		{
    			if (values[counter+1]>values[counter])
    			{
    				temp=values[counter];
    				values[counter+1]=values[counter];
    				values[counter]=temp;
    				swap=true;
    			}
    		}
    		while(swap);
    	}
    	return 0;
    }
    it's giving me this error


    " error C2059: syntax error : 'return "

    please help
    Last edited by Salem; 12-13-2007 at 02:01 AM. Reason: Added code tags

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    So has the formating of your coded helped any? - assuming Salem formated it for you.

    gg

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    5
    i still don't know the solution.....but i learned how to use the [code] thingies....i'm new at this....

  4. #4
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    I didn't know for loops ended with a while()....
    Don't quote me on that... ...seriously

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    5

    thank u

    still not working

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    What, do you expect us to be phsychic? Show the new code!
    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.

  7. #7
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    >> Show the new code!
    Maybe there is no new code. He just wanted to remind us that it doesn't work.

    Anyway, I'm going to bed. My last advice: Check the part on do-while() loops
    Don't quote me on that... ...seriously

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Brad0407 View Post
    >> Show the new code!
    Maybe there is no new code. He just wanted to remind us that it doesn't work.
    In which case ammanbesaw has not been reading anything we're written. And in which case ammanbesaw can figure out the problems without our help.
    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.

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Your code is not indented correctly. Salem fixed it for you in your first post, so if you go back and read that, then you might find the answer to why it isn't working correctly.

    He didn't make it work, he just made it so that you can see more easily where the problem is.

  10. #10
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Look closer at your outer do-while loop... its quite easy to spot the mistake
    Double Helix STL

  11. #11
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    Do you see anything wrong in statement

    for (counter=0; counter<values[counter-1]; counter++)


    ?????

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by ammanbesaw View Post
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
    	const int SIZE = 5;
    	int values[SIZE], counter, temp;
    	bool swap;
    
    	
    	for (counter=0; counter<SIZE; counter++)
    	{
    		cout<<"please input a number"<<endl;
    		cin>>values[counter];
    	}
    
    	do
    	{	swap = false;
    		for (counter=0; counter<values[counter-1]; counter++)
    		{
    			if (values[counter+1]>values[counter])
    			{
    				temp=values[counter];
    				values[counter+1]=values[counter];
    				values[counter]=temp;
    				swap=true;
    			}
    		}
    		while(swap);
    	}
    	return 0;
    }
    it's giving me this error


    " error C2059: syntax error : 'return "

    please help
    There it is.
    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.

  13. #13
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    He's also going to get a crash because he's trying t o check an out-of-bounds array member. When counter = 0, he's trying to check

    counter=0; counter<values[counter-1];

    which is values[-1] !!!

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Probably not a crash, but nevertheless not a good thing.
    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.

  15. #15
    Registered User
    Join Date
    Nov 2007
    Location
    void
    Posts
    3
    Change
    Code:
    		}
    		while(swap);
    	}
    to
    Code:
    		}
    	
    	} while(swap);
    The while statement should be after the closing bracket from do.



    And I did get a crash in the middle of execution most likely because of what you guys just said (about out o' bounds array member)
    Last edited by nat1192; 12-13-2007 at 06:54 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. new problem with class
    By jrb47 in forum C++ Programming
    Replies: 0
    Last Post: 12-01-2006, 08:39 AM
  2. DirectX dll Final Debug and Final Retail
    By hdragon in forum Tech Board
    Replies: 0
    Last Post: 11-15-2005, 09:46 PM
  3. Exam of programming
    By GanglyLamb in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 01-15-2005, 03:40 PM
  4. What do you think of my exam?
    By axon in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 12-03-2004, 08:30 PM
  5. reviewing for final exam, need help with this question
    By jlmac2001 in forum C++ Programming
    Replies: 12
    Last Post: 11-26-2003, 08:37 AM