|
-
February 21st, 2015, 04:08 PM
#1
taking decimal input from the user in c++
I want the input for the price in decimal format(15.00). If the input is in integer format then I want to convert it to decimal format.
The maximum price for a sale is 999.99 and minimum is 0.00.
I have tried so far:
Code:
#include<iostream>
using std::cout;
using std::cin;
void main(){
float eventPrice;
bool cPrice = true;
while (cPrice)
{
cout << "Please enter the event ticket price:";
cin >> eventPrice;
if (eventPrice <= 999.99 && eventPrice>=0) cPrice = false;
else
{
cout << "Invlaid price. Try again!!";
}
}
cout << "the price is:";
cout << eventPrice;
}
Avalid input will be:
1.8,
0.8,
0.00,
0,
9,
99
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|