2014May14 - CPPS - Visual Studio Lab8a.c

1 min read

Deviation Actions

Ongpohhuatiloveu2's avatar
Published:
4.6K Views
#include<stdio.h>
#define LIMIT 6178
void main (void)
{
       //Lab8a.c
       int number,total,difference,count;
       printf("Keep entering number between 10 and 1000\n");
       printf("At each entry, cummulative total is tallied\n");
       printf("The objective is Keep entering number between 10 and 1000 until it exceed LIMIT\n");
       total=0;//initialize starting value
       count=0;//initialize count
       difference=0,number=0;
       do
       {                                 
              printf("Keep entering number between 10 and 1000\n");//prompt & capture numbers
              scanf("%d",&number);
              if(number=0){printf("Exiting!!!\n");break;}
              else if(number<10 || number>1000){printf("Invalid!!!\n");continue;}//if invalid continue at while();
              total=total+number;//cummulative total
              difference=LIMIT-total;
              count++;//increment count (tracking no of entries)
       }while(number!=0 && count<7 && total<LIMIT);//repeat if count not exceeded && num !=0
       if(total<=LIMIT)
              printf("Total is %d and Difference is %d and Valid entries is %d\n",total,difference,count);
       else
              printf("Total is %d and Difference is %d and Valid entries is %d\nGame Over",total,difference,count);
}
© 2014 - 2024 Ongpohhuatiloveu2
Comments0
Join the community to add your comment. Already a deviant? Log In