Can isalpha() check floating point variables, here is my code.
don't worry about the for loop at the end and all that its only the isalpha I'm having trouble with.Code:#include <iostream.h> #include <conio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main(void) { //Declare the variables float cost, quant, price, vat, full, temp; int length, count; char yesno, vats[10]; while (yesno != 'n' && yesno != 'N') { //Get info from user clrscr(); gotoxy(20, 12); cout<<"Please enter the price of the product: "; cin>>cost; if (isalpha(cost)) { cout<<"Thats Wrong"; } clrscr(); gotoxy(20, 12); cout<<"Please enter the quantity of products: "; cin>>quant; if (isalpha(quant)) { cout<<"Thats Wrong"; } clrscr(); gotoxy(20, 12); cout<<"Please enter your rate of vat: "; cin.ignore(); cin.getline(vats, 10); length=strlen(vats); if (length == 0) { temp = 17.5; } else { temp=atof(vats); } //do the calculation temp= temp / 100; price= cost * quant; vat= cost * quant * temp; full= price + vat; clrscr(); gotoxy(20, 12); //give the answer cout<<"The price of "<<quant<<" product(s) at "<<cost<<" each = £"<<price; gotoxy(20, 14); cout<<"The vat at "<<temp*100<<"% = £"<<vat; gotoxy(20, 16); cout<<"Price plus vat = £"<<full; gotoxy(20, 19); cout<<"Would you like to use the program again? "; cin>>yesno; cout<<"\n"; } clrscr(); gotoxy(20, 12); cout<<"Thankyou Bye!"; for (count=0; count<=20000; count++) { for (int j=0; j<=15000; j++) { } } return 0; }



LinkBack URL
About LinkBacks


