Start New Discussion within our Software Development Community
void ADD_QUOTE(){
     do{
        printf("\nPlease enter Length:\n");
        scanf(" %d ", &length);
            }while(scanf(" %d ", &length)<200 || scanf(" %d ",&length)>4000);
       {
        while ((length[count] = getchar()) != '\n')
            putchar(length[count]);
            }
            return;                   
    do {
        printf("\nPlease enter Size:\n");
        scanf(" %d ", &size);
            }while (size[count]<200 || size[count]>4000);

    do {
        printf("\nEnter which Board type you want: 'A'-4mm Standard, 'B'-4mm Thickened, 'C'-6mm Standard, 'D'-6mm Thickened:\n");
        scanf(" %c ", &types);
            }while (types[count] == 'a' || types[count] == 'A' || types[count] == 'b' || types[count] == 'B' || types[count] == 'c' || types[count] == 'C' || types[count] == 'd' || types[count] == 'D');

    do {
        printf("\nPlease enter Quantity:\n");
        scanf(" %d ", &quantity);
            }while (quantity<0);

  while(getchar() != '\n');
  numberboards++;   
}

Ummm, before you guys say anything, im a yr11 at school who reallys needs help with this code...
im trying to add a input validator but i cant find anything online

if you need to see the full code it is linked on the bottom...
(although it would really help me if you could tell me what is wrong with it) =)

Thanks

Attachments
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAXARRAYSIZE  100
#define MAXSIZE1  5.50
#define FOUR_STAND  0.0000825
#define FOUR_TOUGH  0.0001090
#define SIX_STAND  0.0001155
#define SIX_TOUGH  0.0001685

int numberwindows=0;
int height[MAXARRAYSIZE];
int width[MAXARRAYSIZE];
int quantity[MAXARRAYSIZE];
char types[MAXARRAYSIZE];
int count=0;
float base_cost = 5.50;
float subtotal;
float total;

void ADD_QUOTE();
void DISPLAY_ALL_QUOTES();
void EDIT_QUOTE(int);
void SAVE_FILE();

int main(){
	char operation='?';
	while(operation !='Q'&& operation !='q'){
		printf("\n(A)dd a quote, (D)isplay all quotes, (E)dit any quote, (S)ave order into a file, (and (Q)uit\n");
		scanf("%c", &operation);
		while(getchar() !='\n');
		if(operation=='a'||operation=='A'){
			ADD_QUOTE();
			DISPLAY_ALL_QUOTES();
		}else if(operation=='d'||operation=='D'){
			DISPLAY_ALL_QUOTES();
		}else if (operation=='e'||operation=='E'){
			printf("\nEnter which index you want to edit.\n");
			int indextoedit;
			scanf(" %d ", &indextoedit);
			while(getchar() !='\n');
			EDIT_QUOTE(indextoedit);
			DISPLAY_ALL_QUOTES();
		}else if (operation=='s'||operation=='S'){
			SAVE_FILE();
			DISPLAY_ALL_QUOTES();
		}
	}	
}

void ADD_QUOTE(){
     do{
		printf("\nPlease enter Width:\n");
		scanf(" %d ", &width);
			}while(scanf(" %d ", &width)<200 || scanf(" %d ", &width)>4000);
       {
        while ((width[count] = getchar()) != '\n')
            putchar(width[count]);  // dispose of bad input
            }
            return;                   
   	do {
		printf("\nPlease enter Height:\n");
		scanf(" %d ", &height);
			}while (height[count]<200 || height[count]>4000);
		
	do {
		printf("\nEnter which Window type you want: 'A'-4mm Standard, 'B'-4mm Toughened, 'C'-6mm Standard, 'D'-6mm Toughened:\n");
		scanf(" %c ", &types);
			}while (types[count] == 'a' || types[count] == 'A' || types[count] == 'b' || types[count] == 'B' || types[count] == 'c' || types[count] == 'C' || types[count] == 'd' || types[count] == 'D');
		
	do {
        printf("\nPlease enter Quantity:\n");
		scanf(" %d ", &quantity);
            }while (quantity<0);
            			
  while(getchar() != '\n');
  numberwindows++;	
}


void DISPLAY_ALL_QUOTES(){
	system("clear");
    int count=0;
	float subtotal=0, total=0;
		    printf("\nI) \tWindow Type     \tDiemensions    \tQuantity   \tSub Total\n--------------------------------------------------------------------------------"); 
	while(count < numberwindows){
		if (types[count] == 'a' || types[count] == 'A'){
			subtotal = width[count] * height[count] * FOUR_STAND * quantity[count] + base_cost * quantity[count];
			printf("\n%d)\t4mm Standard    \t %d x \t %d     \t %d   \t\t\t %.2f,", width[count], height[count], quantity[count], subtotal); 
        }else if (types[count] == 'b' || types[count] == 'B'){
			subtotal = width[count] * height[count] * FOUR_TOUGH * quantity[count] + base_cost * quantity[count];
			printf("\n%d)\t4mm Toughened   \t %d x \t %d     \t %d   \t\t\t %.2f,", width[count], height[count], quantity[count], subtotal);
		}else if (types[count] == 'c' || types[count] == 'C'){
			subtotal = width[count] * height[count] * SIX_STAND * quantity[count] + base_cost * quantity[count];
			printf("\n%d)\t6mm Standard    \t %d x \t %d     \t %d   \t\t\t %.2f,", width[count], height[count], quantity[count], subtotal);
		}else if (types[count] == 'd' || types[count] == 'D'){
			subtotal = width[count] * height[count] * SIX_TOUGH * quantity[count] + base_cost * quantity[count];
			printf("\n%d)\t6mm Toughened   \t %d x \t %d     \t %d   \t\t\t %.2f,", width[count], height[count], quantity[count], subtotal);
      }else{
			subtotal=0;
	  } 	
      total+=subtotal;
      count++;
    }
    printf("\nGrand total = %.2f", total);
}   
   
void EDIT_QUOTE(int editthis){
	printf("\nWhat would you like to edit? Enter (W)idth, (H)eight, (Q)uantity and (T)ype?:\n");
	scanf("%c", &types[editthis]);
	char operation='?';
	scanf("%c", &operation);
		while(getchar() !='\n');
		if(operation=='w'||operation=='W'){
			do {
				printf("\nPlease enter Width:\n");
				scanf(" %d ",&width[editthis]);
					}while (width[editthis]<200 || width[editthis]>4000);
			
		}else if(operation=='h'||operation=='H'){
			do {
				printf("\nPlease enter Height:\n");
				scanf(" %d ",&height[editthis]);
					}while (height[editthis]<200 || height[editthis]>4000);
					
		}else if (operation=='q' || operation=='Q'){
			do {
				printf("\nPlease enter Quantity:\n");
				scanf(" %d ", &quantity[editthis]);
					}while (quantity[editthis]<0);
		        
		}else if (operation=='t' || operation=='T'){       	       
			do {
				printf("\nEnter which Window type you want: 'A'-4mm Standard, 'B'-4mm Toughened, 'C'-6mm Standard, 'D'-6mm Toughened:\n");
				scanf(" %c ", &types);
					}while (types[numberwindows] == 'a' || types[numberwindows] == 'A' || types[numberwindows] == 'b' || types[numberwindows] == 'B' || types[numberwindows] == 'c' || types[numberwindows] == 'C' || types[numberwindows] == 'd' || types[numberwindows] == 'D');   
                    
		}else{
			while(getchar() !='\n');          
         }
}		
		

void SAVE_FILE(){
	printf("\nEnter the File name\n");
	char filename[40];
	gets(filename);
	FILE *fp;
	fp = fopen(filename, "w");
	int count=0;
	float subtotal=0, total=0;
	while(count < numberwindows){
		if (types[count] == 'a' || types[count] == 'A'){
			subtotal =(width[count] * height[count] * FOUR_STAND * quantity[count]) + (base_cost * quantity[count]);
			fprintf(fp, "\n4mm Standard  \t %d x \t %d    \t %d  \t %.2f,", width[count], height[count], quantity[count], subtotal); 
        }else if (types[count] == 'b' || types[count] == 'B'){
			subtotal =(width[count] * height[count] * FOUR_TOUGH * quantity[count]) + (base_cost * quantity[count]);
			fprintf(fp, "4mm Toughened   \t %d x \t %d    \t %d  \t %.2f,", width[count], height[count], quantity[count], subtotal);
		}else if (types[count] == 'c' || types[count] == 'C'){
			subtotal =(width[count] * height[count] * SIX_STAND * quantity[count]) + (base_cost * quantity[count]);
			fprintf(fp, "6mm Standard   \t %d x \t %d    \t %d  \t %.2f,", width[count], height[count], quantity[count], subtotal);
		}else if (types[count] == 'd' || types[count] == 'D'){
			subtotal =(width[count] * height[count] * SIX_TOUGH * quantity[count]) + (base_cost * quantity[count]);
			fprintf(fp, "6mm Toughened   \t %d x \t %d    \t %d  \t %.2f,", width[count], height[count], quantity[count], subtotal);
		}else{
			subtotal=0;
		}
		total+=subtotal;
		count++;
	}
	fprintf(fp, "\nGrand Total:$.2f", total);
	fclose(fp);
	
}
}while(scanf(" %d ", &length)<200 || scanf(" %d ",&length)>4000);

that should be length<200 || length>4000

im trying to add a input validator

the simplest thing I can think of are using if-else statements

This article has been dead for over six months. Start a new discussion instead.