In the following program when it asks for the rate of vat I want to press return and get it to default to 17.5 percent but I can't figure out how to trick cin, if anybody can help it would be appreciated, thanks.
Code:
/*Program to work out the price of any quantity
of products at any price, plus any rate of vat*/
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
void main()
{
//Declare the variables
float cost, quant, price, vat, full, temp;
int length;
char yesno, vats[10];
while (yesno != 'n' && yesno != 'N')
{
//Get info from user
clrscr();
cout<<"Please enter the price of the product: ";
cin>>cost;
cout<<"\n\n";
cout<<"Please enter the quantity of products: ";
cin>>quant;
cout<<"\n\n";
cout<<"Please enter your rate of vat: ";
cin>>vats;
length=strlen(vats);
cout<<length;
if (length == 0)
{
temp = 17.5;
}
else
{
temp=atof(vats);
}
cout<<"\n\n\n";
//do the calculation
temp= temp / 100;
price= cost * quant;
vat= cost * quant * temp;
full= price + vat;
//give the answer
cout<<"The price of "<<quant<<" product(s) at "<<cost<<" each = £"<<price<<"\n\n"
"The vat = £"<<vat<<"\n\n"
"Price plus vat = £"<<full<<"\n\n";
cout<<"Would you like to use the program again? ";
cin>>yesno;
cout<<"\n";
}
clrscr();
cout<<"Thankyou Bye!";
}