Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

A little help would be nice...

Name: Anonymous 2010-05-01 5:17

Hello /prog/rammers.

Can someone help me with a C dilemma I currently have?

We have to make a program that calculates how many ones, fives and tens you need given a whole number amount.

Hints, anyone?

Name: Anonymous 2010-05-01 5:20


while num>0
 if num>=10
  tens++
  num-=10
  next
 if num>=5
  fives++
  num-=5
  next
 if num>=1
  ones++
  num-=1
  next

Name: Anonymous 2010-05-01 5:24

I would do something like this:

if(num >= 10) {
   while(num >= 10) {
      num -= 10;
      countTens++;
   }
}
if(num >= 5) {
   while(num >= 5) {
      num -= 5;
      countFives++;
   }
}
if(num >= 1) {
   while(num >= 1) {
      num--;
      countOnes++;
   }
}

Name: Anonymous 2010-05-01 7:33

may be borked; if it is, your new homework assignment is to fix it
#include <stdio.h>
#include <ctype.h>
char numberin[9];
int number;
int tens = 0;
int fives = 0;
int ones = 0;

int main(int argc, char *argv[])

{
   while(!isdigit(numberin)) {
      printf("\nPlease input a number: ");
      fgets(numberin, sizeof(numberin), stdin);
   }
   sscanf(numberin, "%d", &number);
   while(number > 0) {
      if(number > 10) {
         tens++;
         number -= 10;
      } else if(number > 5) {
         fives++;
         number -= 5;
      } else {
         ones++;
         number -= 1;
      }
   }
   printf("\nTens: %d", tens);
   printf("\nFives: %d", fives);
   printf("\nOnes: %d", ones);
  
   return(0);
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List