Thread: Expected bracket and unterminated string problem

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    4

    Expected bracket and unterminated string problem

    I am building a program which accepts a number between 5 and 95 and sorts that number into change of 50-20-10 and 5 cent pieces.
    It has the errors:

    line 3- ) expected
    line 6- unterminated string or character constant.
    I am confused on how to fix these errors.

    Code:
    #include <stdio.h>
    
    int takenum(int &num)
    	{
    	printf("Please input change:");
    	scanf("%d%*c", &num");
    	return(num);
    	}
    	
    int calc(int num, int fifty, int twenty, int ten, int five)
    {
    		while(num >= 5 && num <= 95)
    	{
    		if(num >= 50)
    		{
    			fifty++;
    			num-=50;
    		}
    		else
    			if(num >= 20)
    			{
    				twenty++;
    				num-=20;
    			}
    			else
    				if(num >= 10)
    				{
    					ten++;
    					num-=10;
    				}
    				else
    					if(num >= 5)
    					{
    							five++;
    						num-=5;
    					}
    	}
    	return(fifty, twenty, ten, five);
    }
    
    void print(int fifty, int twenty, int ten, int five)
    {
    	printf("Number of 50 cents %d", fifty);
    	printf("Number of 20 cents %d", twenty);
    	printf("Number of 10 cents %d", ten);
    	printf("Number of 5 cents %d", five);
    }
    
    int main()
    {
    
    	int takenum(int num);
    	int calc(int num, int fifty, int twenty, int ten, int five);
    	void print(int fifty, int twenty, int ten, int five);
    	return(0);
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Is this supposed to be C or C++? You posted in the C programming forum, but the reason for the error is that you are using C++ syntax.
    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
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Code:
    int takenum(int &num)
    	{
    	printf("Please input change:");
    	scanf("%d%*c", &num");
    	return(num);
    	}
    	
    int calc(int num, int fifty, int twenty, int ten, int five)
    {
                //you can't do this. Only 1 value is allowed to be returned
    	return(fifty, twenty, ten, five);
    }
    I suggest you re-read through your textbook or take a look at the tutorials we have available at this site.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error:unterminated character constant
    By Figen in forum C Programming
    Replies: 6
    Last Post: 01-31-2011, 02:08 PM
  2. Replies: 2
    Last Post: 12-19-2010, 11:36 PM
  3. Bracket select
    By DrSnuggles in forum C++ Programming
    Replies: 18
    Last Post: 12-18-2007, 07:39 AM
  4. returning an appropriate string for an expected int value ??
    By Neildadon in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2003, 12:35 PM
  5. Compile Error: Unterminated character constant??
    By JamMan in forum C++ Programming
    Replies: 6
    Last Post: 11-14-2001, 04:52 PM