c++ starting programs of book
c++ starting programs of book
#include <iostream>
using namespace std;
int main() {
int player1, player2;
char playAgain;
do {
cout<<"Player1: enter 1 for scissors, 2 for paper, 3 for stone";
cin>> player1;
if (player1 == player2) {
cout << "It's a tie!" << endl;
} else if ((player1 == 1 && player2 == 2) || (player1 == 2 && player2 == 3)
|| (player1 == 3 && player2 == 1)) {
cout << "Player 1 won!" << endl;
} else {
cout << "Player 2 won!" << endl;
}
cout << "Do you want to play again? (y/n): ";
cin >> playAgain;
} while ((playAgain=='y') || (playAgain=='Y'));
cout<<"game over";
return 0;
}
int main() {
int player1, player2;
char playAgain;
do {
// Prompt and input for Player 1
cout << "Player 1, enter 1 for Scissors, 2 for Paper, or 3 for Stone: ";
cin >> player1;
return 0;
}
int main() {
double grams;
return 0;
}
int main() {
double conversionRate;
return 0;
}
int main() {
int number;
do {
// Prompt the user for a positive integer
cout << "Enter a positive integer (or 0 to exit): ";
cin >> number;
if (number > 0) {
// Display the times table for the entered integer
cout << "Times Table for " << number << ":" << endl;
return 0;
}
int main() {
int age;
return 0;
}
int main() {
// Declare and initialize the array
float values[] = {2.6, 3.4, 5.7, 1.855, 10.7, 20.4, 4.621, 7.86, 10.7, 20.56,
13.23, 11.653, 6.48};
return 0;
}
Function usage:
#include <iostream>
using namespace std;
int main() {
// Declare and initialize the array with 10 numbers between 1 and 50
int numbers[ARRAY_LENGTH] = {10, 25, 5, 38, 7, 42, 15, 30, 20, 49};
int limitValue = 30;
// Display values exceeding the limit before applying the Limit function
DisplayBig(numbers, ARRAY_LENGTH, limitValue);
// Display values exceeding the limit after applying the Limit function
DisplayBig(numbers, ARRAY_LENGTH, limitValue);
// Display values exceeding the limit after the Limit function (should not
display anything)
DisplayBig(numbers, ARRAY_LENGTH, limitValue);
return 0;
}