1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
so the goal is to get my program to say bad input and ask for the input again if the characters input are not s, c, g, S, C, G, however ive tried every configuration i know and i can either get it to accept nothing, accept everything, or do nothing the first 2 times you enter something and then accept anything... please help me with anything you can i would be so grateful, this was just the last thing i tried
#include <cmath>
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
char ride;
char s, S;
char c, C;
char g, G;
int startHour;
int startMinute;
int endHour;
int endMinute;
int rideTime;
rideTime = endHour - startHour;
cout << "Name: Brandon Holtz\n";
cout << "Week 4 Program B\n";
cout << "CRN 26670\n";
cout << "This program will calculate the amount due "
<< "\n after a rickshaw ride.\n"
<< " \nto calculate fare for a single ride, input S (or s) "
<< " \nto calculate fare for a couples ride, input C (or c )"
<< " \nto calculate fare for a group ride, input G ( or g)"
<< " \n\nInput S, C, or G \n";
cin >> ride ;
if (ride ==s||c||g||S||C||G)
{
ride =1;
cin >> ride;
}
if (ride!= s||c||g||S||C||G)
ride = 0;
cout << "bad input ";
cout << "\ninput an int " ;
cin.clear();
cin.ignore (10,'\n');
cin >> ride;
cout << fixed << showpoint;
cout << setprecision (2);
if (ride == 's' || ride== 'S')
{
cout << "\nEnter time the ride started seperating hour and minutes by a space.\n";
cin >> startHour >> startMinute;
cout << "\nEnter time the ride ended seperating hour and minutes by a space. \n";
cin >> endHour >> endMinute;
cout << endHour - startHour << "h " << endMinute - startMinute << "m\n";
if (endHour - startHour == 0||1||2||3||4||5||6||7||8||9 && endMinute - startMinute > 30)
{
cout << "\nThe ride will be $" << 7 + (1.50 * ((endMinute - startMinute)- 30));
}
if (endHour - startHour == 0 && endMinute - startMinute <= 30)
{
cout << "\nThe ride will be $7.00 please\n";
}
system("pause");
return EXIT_SUCCESS;
}
if (ride== 'c' || ride== 'C');
{
cout << "\nEnter time the ride started seperating hour and minutes by a space.\n";
cin >> startHour >> startMinute;
cout << "\nEnter time the ride ended seperating hour and minutes by a space. \n";
cin >> endHour >> endMinute;
cout << endHour - startHour << "h " << endMinute - startMinute << "m\n";
{
if (endHour - startHour == 0 && endMinute - startMinute <= 20)
cout << "The ride will be $10.50 please";
}
}
if (ride == 'g' || ride== 'G')
{
cout << "\nEnter time the ride started seperating hour and minutes by a space.\n";
cin >> startHour >> startMinute;
cout << "\nEnter time the ride ended seperating hour and minutes by a space. \n";
cin >> endHour >> endMinute;
cout << endHour - startHour << "h " << endMinute - startMinute << "m\n";
{
if (endHour - startHour == 0 && endMinute - startMinute <= 15)
cout << "\nThe ride will be $16.00 please\n" ;
}
}
system("pause");
return EXIT_SUCCESS
|