Thread: Stupid question

  1. #1
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179

    Stupid question

    Well they say that there is no such thing as a stupid question...well here I am

    Alright I am learning and reading a book and they were talking abut constants so I decided that it would be interesting to go and check them out and try them for myself, so this is what I came up with:

    Code:
    #include <stdio.h>
    
    unsigned int positive;
    int posAndneg;
    const double decimal1 = 1.123321;
    #define decimal2 = 2.234432;
    double userTotal = positive + posAndneg;
    double userTotalF = userTotal + decimal1 + decimal2; /*First time error occoured*/
    
    main(void)
    {
    	printf("Please enter a positive number: ");
    	scanf("positive");
    	
    	printf("Please enter another number(either positive or negative)");
    	scanf("posAndneg");
    
    	printf("The total of adding both of your numbers together is: %f", userTotal);
    
    	printf("The computer will now add %d and %d to the total of your two numbers", decimal1, decimal2); /*Second time error*/
    
    	printf("The final total is: %d", userTotalF);
    	
    	return 0;
    }
    Now I have made a few small programs to play with things and have managed to fix all of those errors, with some help from the board of course, but this time I am truly lost, here are the errors:

    error C2059: syntax error : '='

    Now I get this one but it appears twice, it appears the first time on the line that has the comment "first time" on it and this I think is just me not knowing about the different types of variables and such so that should be easy for someone who knows.
    Then it appears again on the line that has "second time" on it and I don't get that one at all because I can't seem to find the '=' in it.
    And finally
    syntax error : missing ';' before ')'
    I know what this means and how to fix it but I have no idea where to put the ; , the error appears on the same line as 'Second time'

    If someone can help give a bit of a lesson I would be grateful.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Change this
    >#define decimal2 = 2.234432;
    to this
    >#define decimal2 2.234432

    Also, my compiler moans about
    >double userTotal = positive + posAndneg;
    You need to declare the variables, then, within main(), once you have the users input, apply values to them.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    >scanf("positive");
    >scanf("posAndneg");
    is wrong

    You have some thing called the format specifiers, basically telling scanf what kind of data to read. In your case, it would be:
    Code:
    scanf("%u", &positive);
    scanf("%d", &posAndneg);

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    132
    Is there a place I can know more about those specifiers? I know some of them but not all.
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  5. #5
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    This is just one I found out of many here

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    And here
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Unregistered
    Guest
    while defining the constant variable using define.
    dont use "="

    ex: #define decimal1 1.2222

  8. #8
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    Alright I tried the things that you said and I came up with more problems.

    #1. When I tried to change scanf("posititive") to scanf("%u" &positive) it came up with this:
    '&' : illegal, left operand has type 'char [3]'

    Is this because of the & sign or did I just type something wrong?

    Also I am still getting those syntax errors but I can't seem to find the problem, here is what they are:
    syntax error : missing ')' before ';'
    and
    syntax error : ')'

    I don't know a whole lot but I do know that this means I should just insert a closing bracket in there right?
    Anyways here is my code again(with some changes)

    Code:
    #include <stdio.h>
    
    unsigned int positive;
    int posAndneg;
    const double decimal1 = 1.123321;
    #define decimal2 2.234432;
    double userTotal; /*positive + posAndneg;*/
    double userTotalF; /*userTotal + decimal1 + decimal2;*/
    
    main(void)
    {
    	printf("Please enter a positive number: ");
    	scanf("%u" &positive);
    	
    	printf("Please enter another number(either positive or negative)");
    	scanf("%d" &posAndneg);
    	
    	userTotal = positive + posAndneg;
    	printf("The total of adding both of your numbers together is: %f", userTotal);
    
    	printf("The computer will now add %d and %d to the total of your two numbers", decimal1, decimal2);
    	
    	userTotalF = userTotal + decimal1 + decimal2;
    	printf("The final total is: %d", userTotalF);
    	
    	return 0;
    }
    Thanks again
    Last edited by CAP; 07-03-2002 at 09:23 AM.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  9. #9
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    Code:
    #include <stdio.h>
    
    unsigned int positive;
    int posAndneg;
    const double decimal1 = 1.123321;
    #define decimal2 2.234432/*   ;   */
    double userTotal; /*positive + posAndneg;*/
    double userTotalF; /*userTotal + decimal1 + decimal2;*/
    
    int main(void)
    {
    	printf("Please enter a positive number: ");
    	scanf("%u", &positive);
    	
    	printf("Please enter another number(either positive or negative)");
    	scanf("%d",  &posAndneg);
    	
    	userTotal = (double)positive + (double)posAndneg;
    	printf("The total of adding both of your numbers together is: %f", userTotal);
    
    	printf("The computer will now add %f and %f to the total of your two numbers", decimal1, decimal2);
    	
    	userTotalF = userTotal + decimal1 + decimal2;
    	printf("The final total is: %f", userTotalF);
    	
    	return 0;
    }
    Last edited by shaik786; 07-03-2002 at 09:53 AM.

  10. #10
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    Thanks I will try that, when I get a chance.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  11. #11
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    And when you get the hang of it, try checking the return code from scanf() to ensure the user has entered a valid number.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  12. #12
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    Of course, I am just going to make it and then keep modifying it, simple -yes- but I think it is worthwhile to keep trying anyways, thanks for all the help.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  13. #13
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >thanks for all the help.
    No problem....
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Question Probably
    By Kyrin in forum C Programming
    Replies: 2
    Last Post: 05-07-2006, 12:51 AM
  2. Replies: 7
    Last Post: 11-04-2005, 12:17 AM
  3. Stupid Question
    By digdug4life in forum C++ Programming
    Replies: 22
    Last Post: 05-17-2005, 11:43 AM
  4. stupid, stupid question
    By xelitex in forum C++ Programming
    Replies: 5
    Last Post: 12-22-2004, 08:22 PM
  5. Stupid question: What does Debugger do?
    By napkin111 in forum C++ Programming
    Replies: 6
    Last Post: 05-02-2002, 10:00 PM