Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
10 views5 pages

Questions

The document is a C++ program that prompts users to select a country to display the number of space satellites sent and the number of non-working satellites. It also allows users to choose a planet to see the count of space debris and active satellites. The program includes input validation and error handling for user choices.

Uploaded by

kthamayanthi8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

Questions

The document is a C++ program that prompts users to select a country to display the number of space satellites sent and the number of non-working satellites. It also allows users to choose a planet to see the count of space debris and active satellites. The program includes input validation and error handling for user choices.

Uploaded by

kthamayanthi8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include <iostream.

h>

#include <conio.h>

#include <stdlib.h> // Required for exit()

void main() {

int choice;

clrscr(); // Clear the screen

// First Question: Number of Space Satellites Sent

cout << "Choose a country to see the number of space satellites sent:" << endl;

cout << "1. India" << endl;

cout << "2. USA" << endl;

cout << "3. China" << endl;

cout << "4. Japan" << endl;

cout << "Enter your choice (1-4): ";

cin >> choice;

// Input validation

if (cin.fail()) {

cout << "Invalid input. Please enter a number between 1 and 4." << endl;

cin.clear();

cin.ignore(); //Turbo C++ does not have ignore with stream size, so, ignore all

getch(); //Pause for viewing

exit(1); //Exit program with error

if (choice < 1 || choice > 4) {

cout << "Invalid choice. Please enter a number between 1 and 4." << endl;

getch(); //Pause for viewing

exit(1); //Exit program with error


}

int satellitesSent = 0;

switch (choice) {

case 1:

satellitesSent = 440;

break;

case 2:

satellitesSent = 250;

break;

case 3:

satellitesSent = 150;

break;

case 4:

satellitesSent = 100;

break;

if (satellitesSent > 0) {

cout << "Number of space satellites sent: " << satellitesSent << endl;

// Second Question: Non-Working Satellites

cout << "\nHow many non-working satellites are there? (Select a country)" << endl;

cout << "1. India" << endl;

cout << "2. USA" << endl;

cout << "3. China" << endl;

cout << "4. Japan" << endl;

cout << "Enter your choice (1-4): ";

cin >> choice;


// Input validation

if (cin.fail()) {

cout << "Invalid input. Please enter a number between 1 and 4." << endl;

cin.clear();

cin.ignore(); //Ignore the stream to avoid the same error.

getch(); //Pause for viewing

exit(1);

if (choice < 1 || choice > 4) {

cout << "Invalid choice. Please enter a number between 1 and 4." << endl;

getch();

exit(1);

int nonWorkingSatellites = 0;

switch (choice) {

case 1:

nonWorkingSatellites = 20;

break;

case 2:

nonWorkingSatellites = 60;

break;

case 3:

nonWorkingSatellites = 80;

break;

case 4:

nonWorkingSatellites = 80;

break;

}
if (nonWorkingSatellites > 0) {

cout << "Number of non-working satellites: " << nonWorkingSatellites << endl;

// Third Question: Space Debris in Planets

cout << "\nSpace debris in which planet?" << endl;

cout << "1. Mars" << endl;

cout << "2. Venus" << endl;

cout << "3. Jupiter" << endl;

cout << "Enter your choice (1-3): ";

cin >> choice;

// Input validation

if (cin.fail()) {

cout << "Invalid input. Please enter a number between 1 and 3." << endl;

cin.clear();

cin.ignore();

getch();

exit(1);

if (choice < 1 || choice > 3) {

cout << "Invalid choice. Please enter a number between 1 and 3." << endl;

getch();

exit(1);

int debrisCount = 0;

int activeSatellites = 0; // Add this line

switch (choice) {
case 1:

debrisCount = 18;

activeSatellites = 7; // Add this line

break;

case 2:

debrisCount = 40;

break;

case 3:

debrisCount = 9;

break;

if (debrisCount > 0) {

cout << "Space debris count: " << debrisCount << endl;

if (choice == 1) { // Check if it's Mars

cout << "Active satellites: " << activeSatellites << endl; // Now prints active satellites

getch(); //Keep the output on screen until a key is pressed.

You might also like