Thread: Can't spot my mistake C

  1. #1
    Registered User
    Join Date
    Aug 2020
    Posts
    2

    Can't spot my mistake C

    I'm trying to make a simple program in C, which asks an input above 10 and prints it on the screen.
    Code:
    #include <cs50.h>
    #include <stdio.h>
    
    int main(void)
    {
      int h;
      do {
        int h = get_int("mispar\n");
      }
      while (h < 10);
      printf("%i\n", h);
    }
    and it replies me with:
    declaration shadows a local variable [-Werror,-Wshadow]
    int h =get_int("mispar\n");
    ^
    number.c:6:5: note: previous declaration is here
    int h;
    ^

    \

    Last edited by khjh15; 08-19-2020 at 09:58 AM. Reason: forgot something

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,302
    So make line 8 just
    h = get_int("mispar\n");
    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.

  3. #3
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,138
    remove the int before the h =

  4. #4
    Registered User
    Join Date
    Aug 2020
    Posts
    2
    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I can't spot my mistake...
    By awsdert in forum C Programming
    Replies: 213
    Last Post: 1 Week Ago, 07:32 AM
  2. can anyone help to spot mistake in the code
    By chess_queen in forum C Programming
    Replies: 1
    Last Post: 10-21-2012, 10:37 AM
  3. Can you spot my mistake?
    By Brewer in forum C Programming
    Replies: 13
    Last Post: 11-12-2006, 12:50 PM

Tags for this Thread