-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.cpp
More file actions
122 lines (99 loc) · 3.04 KB
/
app.cpp
File metadata and controls
122 lines (99 loc) · 3.04 KB
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
115
116
117
118
119
120
121
122
#include <iostream>
#include <string>
#include <cstdlib> // For rand()
#include <ctime> //
#include <iostream>
#include <string>
using namespace std;
string email, username, password, confirmPassword;
void signUp() {
cout << "Enter Email address: ";
cin >> email;
cout << "Enter Password: ";
cin >> password;
cout << "Enter Confirm Password: ";
cin >> confirmPassword;
if (password == confirmPassword) {
cout << "Enter a username: ";
cin >> username;
cout << "Account created successfully!\n";
} else {
cout << "Passwords do not match! Try again.\n";
signUp(); // Recursive call for retry
}
}
#include <cstdlib> // For rand()
#include <ctime> // For time()
void login() {
string inputUsername, inputPassword;
int otp, enteredOTP;
cout << "Enter your username: ";
cin >> inputUsername;
cout << "Enter your password: ";
cin >> inputPassword;
if (inputUsername == username && inputPassword == password) {
srand(time(0)); // Seed for random OTP
otp = rand() % 9000 + 1000; // Generates a 4-digit OTP
cout << "Your OTP is: " << otp << endl;
cout << "Enter OTP to verify: ";
cin >> enteredOTP;
if (enteredOTP == otp) {
cout << "Access Granted! Welcome to your account.\n";
} else {
cout << "Incorrect OTP. Try again.\n";
login(); // Retry login
}
} else {
cout << "Invalid credentials! Try again.\n";
login();
}
}
void bookRide() {
string pickup, destination;
int vehicleType, distance, fare;
cout << "Enter your Pickup Location: ";
cin >> pickup;
cout << "Enter your Destination: ";
cin >> destination;
cout << "Select Vehicle Type:\n";
cout << "1. Car (Rs. 20/km)\n";
cout << "2. Bike (Rs. 10/km)\n";
cout << "3. Auto (Rs. 15/km)\n";
cout << "Enter your choice (1-3): ";
cin >> vehicleType;
cout << "Enter estimated distance (in km): ";
cin >> distance;
switch (vehicleType) {
case 1: fare = distance * 20; break;
case 2: fare = distance * 10; break;
case 3: fare = distance * 15; break;
default: cout << "Invalid choice! Try again.\n"; bookRide(); return;
}
cout << "Estimated Fare: Rs. " << fare << endl;
char confirm;
cout << "Confirm Ride? (Y/N): ";
cin >> confirm;
if (confirm == 'Y' || confirm == 'y') {
cout << "Finding your driver...\n";
cout << "Ride Confirmed! Your driver is on the way.\n";
} else {
cout << "Ride cancelled.\n";
}
}
int main() {
int choice;
cout << "Welcome to Online Ride-Booking App\n";
cout << "1. Sign-Up\n2. Login\n";
cin >> choice;
if (choice == 1) {
signUp();
login(); // After sign-up, login immediately
} else if (choice == 2) {
login();
} else {
cout << "Invalid choice!\n";
return 0;
}
bookRide(); // Start ride-booking after login
return 0;
}