Thread: Basic C Assignment for School, advice?

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    2

    Basic C Assignment for School, advice?

    Hey there! I'm new to the C language, don't need to tell me I'm a newbie, I know I suck. >.>

    I'm currently taking a C introductory course and I'm having some trouble with some of these assignments because I don't really have any coding precedence. I'd really appreciate some help. = )

    This first assignment is to find all numbers that follow the cube rule from 100-999.

    The cube rule being, the first digit cubed added to the second digit cube added to the third digit cubed equals the number.

    For example of the cube rule, the number 153 is 1^3 + 5^3 + 3^3 = 153

    The results expected to be printed are -

    153 has the cube property. (1 + 125 + 27)370 has the cube property. (27 + 343 + 0)371 has the cube property. (27 + 343 + 1)407 has the cube property. (64 + 0 + 343)
    This is what I have so far. I've tried to compile it and I know it has errors, though I'm not sure exactly how to fix it. Any help is appreciated! = )

    Code:
    #include <stdio.h>
    
    int main(void)
    {
      int a, b, c, atrip, btrip, ctrip, cubecheck;
    
    
        for (cubecheck = 100; cubecheck <= 999; cubecheck++)
          a = (cubecheck % 10);
          c = (cubecheck / 100);
          b = ((cubecheck - (c*100 + a) )/ 10);
          atrip = (a*a*a);
          btrip = (b*b*b);
          ctrip = (c*c*c);
        
          if(atrip + btrip + ctrip == cubecheck);
          prinf("%i has the cube property. (%i + %i + %i )\n", cubecheck, atrip, btrip, ctrip);
          }
        
      return 0;
    }

  2. #2
    Registered User
    Join Date
    Sep 2012
    Posts
    357
    You for loop extends only 1 line down, not 9 lines: you're missing the opening brace {

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    if(atrip + btrip + ctrip == cubecheck);

    It appears this is one problem. Putting a stray semi-colon here instead of an opening curly brace made the braces unbalanced.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with my school assignment
    By Shazarul in forum C++ Programming
    Replies: 3
    Last Post: 11-16-2011, 08:36 AM
  2. C++ code for school assignment
    By Pupo in forum C++ Programming
    Replies: 3
    Last Post: 03-09-2010, 08:11 AM
  3. Corrections on School assignment...
    By hubris in forum C++ Programming
    Replies: 9
    Last Post: 05-19-2009, 04:54 PM
  4. Help for school assignment
    By Allynia in forum C Programming
    Replies: 9
    Last Post: 04-29-2008, 03:07 PM
  5. School assignment...NEED HELP
    By godfrey270487 in forum C++ Programming
    Replies: 12
    Last Post: 03-09-2006, 02:35 PM