# Answer to Question #37434 in C++ for Nessma

Question #37434

Write a program that takes an integer from the user and displays “True” if and only if the integer is a prime!

number between 1 and 1000. (A prime number is a number that is only divisible by itself).! !

2- Assume that there is a driver of a taxi and he asked you to develop a program for him as the followings:!

• He will enter the information for each trip during his day.!

NOTE: trip's data will be:!

- The income of the trip.!

- The distance of the trip.!

NOTE: the driver will stop the program when he gets a total income in his day that is greater!

than > 300 L.E.!

• Display how many trips he made in his day.!

• Display the total distance he made during his day.!

• Determine which trip was the shortest trip.

number between 1 and 1000. (A prime number is a number that is only divisible by itself).! !

2- Assume that there is a driver of a taxi and he asked you to develop a program for him as the followings:!

• He will enter the information for each trip during his day.!

NOTE: trip's data will be:!

- The income of the trip.!

- The distance of the trip.!

NOTE: the driver will stop the program when he gets a total income in his day that is greater!

than > 300 L.E.!

• Display how many trips he made in his day.!

• Display the total distance he made during his day.!

• Determine which trip was the shortest trip.

Expert's answer

`#include <iostream> `

#include <conio.h>

using namespace std;

int main ()

{

float income;

float distance;

int TripsCounter = 0;

float TotalIncome = 0;

float TotalDistance = 0;

float TheShortestTrip = 1000000 ;

cout<<"Hello dear driver"<<endl;

while (TotalIncome<300)

{

cout<<"Please, enter the income of the trip ($): ";

cin>>income;

cout<<"Please, enter the distance of the trip (km): ";

cin>>distance;

TripsCounter++;

TotalIncome += income;

TotalDistance += distance;

if (distance < TheShortestTrip)

TheShortestTrip = distance;

}

cout<<"So today you have made "<<TripsCounter<<" trips"<<endl;

cout<<"Total distace is: "<<TotalDistance<<" km"<<endl;

cout<<"The shortest trip is "<<TheShortestTrip<<" km"<<endl;

_getch();

return 0;

}

## Comments

## Leave a comment