Question

In: Computer Science

Use C++ language Ask the user for their favorite number. If it isn't 10 and isn't...

Use C++ language

  1. Ask the user for their favorite number. If it isn't 10 and isn't divisible by 3, tell them they made a good choice.
  2. Ask the user how many guests will be arriving, use a while loop to ensure they don't give you negative number of guests. Ask them the name of each guest and output "hello guest" with their name.

3. Ask the user to pick a number between 1 and 100. You (the program) should try and guess the number the user picked. The user can tell you if their number is higher or lower, but that is all. The program should run until the computer guesses correctly.

Solutions

Expert Solution

Answer 1:

#include <iostream>

using namespace std;

int main()
{
int n;
cout<<"Enter number: ";
cin>>n;
if(n!=10 && n%3!=0)
cout<<"You made a good choice: ";
return 0;
}

Answer 2:

#include <iostream>

using namespace std;

int main()
{
int n;
string str;
while(true){
cout<<"Enter how many number of guests are coming: ";
cin>>n;
if(n>0)
break;
cout<<"Number can't be negative: "<<endl;
}
for(int i=0;i<n;i++){
cout<<"Enter guest name: ";
cin>>str;
cout<<"Hello "<<str<<endl;
}
return 0;
}

Answer 3:

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int getRandom(){
   srand(time(0)); //seed random number generator
   int num = rand() % 100 + 1; // random number between 1 and 100
   return num;
}
int getNum(){
   int guess;
cout << "Enter a guess between 1 and 100 : ";
       cin >> guess;
   return guess;
}
int getRes(int g,int n){
   if(g>n)
       return 1;
   else if(g<n)
       return -1;
   else
       return 0;
}
int main()
{
   int num, guess, res = 0,ch=1;
   while(ch){
   num=getRandom();
   cout << "Guess My Number Game\n\n";
  
   do
   {
   //getting random num
       guess=getNum();
       //checking res
       res=getRes(guess,num);
       if (res > 0)
           cout << "Too high!\n\n";
       else if (res < 0)
           cout << "Too low!\n\n";
       else
           cout << "\nCorrect! You got it\n";
   } while (guess != num);
   cout<<"Press 1 to play again..0 to exit: ";
   cin>>ch;

}
   return 0;
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

Use C++ language Create a program which will ask the user to input three songs for...
Use C++ language Create a program which will ask the user to input three songs for a playlist (you may use TV shows or movies, if you prefer). Declare three strings to store each of the songs. Use getline to receive the input. Display output which lists each of the songs (or movies or tv shows), on separate lines, with a title on the first line: My Playlist. Insert three lines of comments at the beginning of the program for...
C LANGUAGE Ask user how many scores there are, then ask for each score. Then calculate...
C LANGUAGE Ask user how many scores there are, then ask for each score. Then calculate the average score and scores below 60. Then display the average score and number of scores below 60
Language C++ Ask the user to enter their weight (in pounds) and their height in inches....
Language C++ Ask the user to enter their weight (in pounds) and their height in inches. Calculate their Body Mass Index (BMI) and tell them whether they are underweight, overweight, or at optimal weight. BMI formula: weight * 703 / (height * height) Optimal weight is a BMI from 19 to 26. Lower is underweight, higher is overweight. Prompts: Enter your weight (in pounds): [possible user input: 144] Enter your height (in inches): [posible user input: 73] Possible Outputs: Your...
Flowchart + Python. Ask the user for a value. Then, ask the user for the number...
Flowchart + Python. Ask the user for a value. Then, ask the user for the number of expressions of that value. Use While Loops to make a program. So then, it should be so that 5 expressions for the value 9 would be: 9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 Flowcharts and Python Code. Not just Python code. I cannot read handwriting....
Write a program using C language that -ask the user to enter their name or any...
Write a program using C language that -ask the user to enter their name or any other string (must be able to handle multiple word strings) - capture the epoch time in seconds and the corresponding nanoseconds - ask the user to type in again what they entered previously - capture the epoch time in seconds and the corresponding nanoseconds -perform the appropriate mathematical calculations to see how long it took in seconds and nanoseconds (should show to 9 decimal...
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
c# language Write a program that takes in a number from the user. Then it prints...
c# language Write a program that takes in a number from the user. Then it prints a statement telling the user if the number is even or odd. If the number is odd, it counts down from the number to 0 and prints the countdown on the screen, each number on a new line. If the number is even, it counts down from the number to 0, only even numbers. For example, if the user enters 5, the output will...
Language: C# Create a new Console Application. Your Application should ask the user to enter their...
Language: C# Create a new Console Application. Your Application should ask the user to enter their name and their salary. Your application should calculate how much they have to pay in taxes each year and output each amount as well as their net salary (the amount they bring home after taxes are paid!). The only taxes that we will consider for this Application are Federal and FICA. Your Application needs to validate all numeric input that is entered to make...
Language C++ Ask the user to enter the name of one primary color (red, blue, yellow)...
Language C++ Ask the user to enter the name of one primary color (red, blue, yellow) and a second primary color that is different from the first. Based on the user's entries, figure out what new color will be made when mixing those two colors. Use the following guide: red and blue make purple blue and yellow make green yellow and red make orange If the user enters anything that is outside one of the above combinations, return an error...
for python 3 a. Ask the user to enter 10 numbers. Each number is stored in...
for python 3 a. Ask the user to enter 10 numbers. Each number is stored in a list called myList. Compute and print out the sum and average of the items in the list. Print the numbers that are divisible by 2 from myList. b. Instead of using a list to store the numbers, create a loop to accept the numbers from the user, and find the average of all the numbers. Hint: use an accumulator to store the numbers...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT