Question

In: Computer Science

C++ please 1. Write a do while loop that continually loops until the user enters a...

C++ please


1. Write a do while loop that continually loops until the user enters a single digit between 0 and 9. There should only be one prompt for the user to enter a number inside the loop.

2. Write a simple 4 function calculator using a switch statement. The program should switch on the operator: +, -, *, /. The user should enter two numbers (any type is fine) and then enter an operator and the program should perform the calculation indicated.

3. Write a program that has the user enter a numeric scores (0-100) and then, using the conditional operator, display whether or not the student made a passing score. A passing score is 70 or above.

Solutions

Expert Solution

1)

#include<iostream>
#include<math.h>
using namespace std;


int main()
{

int n=100;
do
{
    cout<<" enter n:";
    cin>>n;
    if(n>=0 && n<=9)
        break;
    else
        cout<<" looping...";
}while(1);
}


2)

#include<iostream>
#include<math.h>
using namespace std;
int add(int a ,int b)
{
    return a+b;
}
int sub(int a ,int b)
{
    return a-b;
}
int mul(int a,int b)
{

    return a*b;
}
float div(int a ,int b)
{
    return a/b;
}
int main()
{
int a=0,b=0;
char opr;
cout<<"enter first number";
cin>>a;
cout<<"enter second number";
cin>>b;
cout<<"enter operation";
cin>>opr;
float result =0 ;
switch(opr)
{
    case '+': result = add(a,b);break;
     case '-': result = add(a,b);break;
      case '*': result = add(a,b);break;
       case '/':result = add(a,b);break;
       default:"wrong operation entered";
}
cout<<" result = "<<result;
}


3)

#include<iostream>
#include<math.h>
using namespace std;

int main()
{
int score;
cout<<"enter score";
cin>>score;

if(score>=70 && score <=100)
    cout<<"you passed";
else if(score >=0 && score <70)
    cout<<"you failed";
else
    cout<<"invalid value for score entered";
}



Related Solutions

Write a C++ program that reads numbers from the user until the user enters a Sentinel....
Write a C++ program that reads numbers from the user until the user enters a Sentinel. Use a Sentinel of -999. Ignore all negative numbers from the user input. Do the following: Output the sum of all even numbers Output the sum of all odd numbers Output the count of all even numbers Output the count of all odd numbers You must use loops and numbers to do this. You must not use any arrays or vectors for this program.
Python Exercises = Sentinel Values and While Loops #Exercise 1 #Write a while loop with a...
Python Exercises = Sentinel Values and While Loops #Exercise 1 #Write a while loop with a sentinel value #This while loop ends when the user enters a 1, the sentinel value #Assign the number 8 to a variable which will serve as the sentinel value #Condition: while variable is not equal to 1 #Action: display the number assigned to the variable #Use an input statement (no prompt) to ask the user for a number and assign this number to the...
CODE MUST BE IN C++ (please use for loop) write a program that loops a number...
CODE MUST BE IN C++ (please use for loop) write a program that loops a number from 1 to 10 thousand and keeps updating a count variable (count variable starts at 0 ) according to these rules: n1 = 14 n2 = 54 n3 = 123 if the number is divisible by n1, increase count by 1 if the number is divisible by n2, increase count by 2 if the number is divisible by n3, increase count by 3 if...
First, write a program to loop asking for a number from the user until the user...
First, write a program to loop asking for a number from the user until the user inputs a zero or until the user has input 50 numbers. Store each value in an array except the values that are divisible by 5 and display all stored values. Determine how many of the values stored in the array were divisible by 10 and display result. Next, write a function getMinMax that accepts an array of floats and the size of the array,...
Do the following lab by while or Do-while loop. question: Write a c++ program that asks...
Do the following lab by while or Do-while loop. question: Write a c++ program that asks students to enter 3 valid grades and then calculate the average and print it. if the user enters the invalid grade you should print the error message and get the new grade. Hint1: each time your program ask the following question: "Do you want to calculate another average?" and if the answer to this question is "Y" or "y" then you should continue. Hint2:...
C++ while loop Exercise Write a program that continues to ask the user to enter any...
C++ while loop Exercise Write a program that continues to ask the user to enter any set of numbers, until the user enters the number -1. Then display the total sum of numbers entered and their average. (note that you need to define a counter that counts how many numbers so the average = (sum/n) where n is your counter total. #include <iostream> using namespace std; int main() { int number, n=0, sum=0; cout << "Enter a number to start...
Write a do-while loop IN JAVA to build a Pokémon game Prompt the user for two...
Write a do-while loop IN JAVA to build a Pokémon game Prompt the user for two names one for their Pokémon, and one for the computers Pokémon Make two integer variables to hold the HP of each Pokémon, HP should be 20 for both Pokémon’s. Use Math.random() to determine the amount of damage caused, and which move the computer will select. The range of damage that can be done is up to you. Output to the user an attack menu...
Write a C++ code using while loop which is getting the two integers from the user,...
Write a C++ code using while loop which is getting the two integers from the user, and output how many numbers are multiples of 5, and how many numbers are multiples of 7 between the two integers (inclusive).
In C program, Use "do...while" and "for" loops to write a program that finds all prime...
In C program, Use "do...while" and "for" loops to write a program that finds all prime numbers less than a specified value.
Problem: Construct a C program that will make use of user-defined functions, the do/while loop, the...
Problem: Construct a C program that will make use of user-defined functions, the do/while loop, the for loop, and selection. Using a do/while loop, your program will ask/prompt the user to enter in a positive value representing the number of values they wish to have processed by the program or a value to quit/exit. If the user enters a 0 or a negative number the program should exit with a message to the user indicating they chose to exit. If...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT