Thread: Hey guys im a noob please help

  1. #1
    Registered User
    Join Date
    Sep 2018
    Posts
    3

    Hey guys im a noob please help

    Im trying to shorten a bit of code,
    Code:
    printf("Please enter your students exam mark seperated by a space\n");
      scanf("%d %d %d %d %d %d %d %d %d %d", &grade[1], &grade[2], &grade[3], &grade[4], &grade[5], &grade[6], &grade[7], &grade[8], &grade[9], &grade[0]);
    The code works but its a bit annoying having all of these different variables like this in another bit of code ive used a for loop,
    Code:
       for (i=0; i<10; i++){
        sum += grade[i];
       }
    This adds up all the variables. I was wondering if there was something like this is could use in my scanf function.
    Thanks.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Try in the same kind of loop
    Code:
    scanf("%d",&grade[i]);
    Also, this:
    How To Ask Questions The Smart Way
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hey guys
    By Cdd101 in forum C Programming
    Replies: 9
    Last Post: 10-20-2013, 06:01 PM
  2. Hey guys can i get some help please?
    By Damienmc++keown in forum C++ Programming
    Replies: 3
    Last Post: 04-20-2011, 06:53 PM
  3. Hi guys
    By Renegade in forum C++ Programming
    Replies: 14
    Last Post: 07-01-2005, 03:11 PM
  4. please help guys!
    By Owain1602 in forum C Programming
    Replies: 7
    Last Post: 03-02-2004, 04:06 PM
  5. What do you guys think...
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 01-22-2004, 12:57 PM

Tags for this Thread