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 series of codes using WHILE loops C++ 1. Ask the user for a number...
Write a series of codes using WHILE loops C++ 1. Ask the user for a number and adds even numbers for 1 to the user entered number. 2. Write another piece of code that asks the user for 2 numbers and adds up the numbers between and including the numbers. 3. Write another piece of code that asks user for a file name and then add up all the numbers for the file.
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.
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 (other than the sentinel). Do the following: 1. Output the sum of all even numbers 2. Output the sum of all odd numbers 3. Output the count of all even numbers 4. Output the count of all odd numbers You must use alternation ('if' statements), loops and simple calculations to do...
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...
Write a program that uses loops (both the for-loop and the while loop). This assignment also...
Write a program that uses loops (both the for-loop and the while loop). This assignment also uses a simple array as a collection data structure (give you some exposure to the concept of data structure and the knowledge of array in Java). In this assignment, you are asked to construct an application that will store and retrieve data. The sequence of data retrieval relative to the input is Last In First Out (LIFO). Obviously, the best data structure that can...
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...
Create a C++ program which will prompt the user to enter a password continually until the...
Create a C++ program which will prompt the user to enter a password continually until the password passes the following tests. Password is 6 chars long Password has at least 1 number If the input does not match the tests, it will input a specific error message. "Pass must be 6 chars long." If the input is allowed, print a message saying "Correct Password Criteria."
Write a C# console program that continually asks the user "Do you want to enter a...
Write a C# console program that continually asks the user "Do you want to enter a name (Y/N)? ". Use a "while" loop to accomplish this. As long as the user enters either an upper or lowercase 'Y', then prompt to the screen "Enter First and Last Name: " and then get keyboard input of the name. After entering the name, display the name to the screen. --- Create a Patient class which has private fields for patientid, lastname, firstname,...
Write a C# console program that continually asks the user "Do you want to enter a...
Write a C# console program that continually asks the user "Do you want to enter a name (Y/N)? ". Use a "while" loop to accomplish this. As long as the user enters either an upper or lowercase 'Y', then prompt to the screen "Enter First and Last Name: " and then get keyboard input of the name. After entering the name, display the name to the screen.
Write a C# console program that continually asks the user "Do you want to enter a...
Write a C# console program that continually asks the user "Do you want to enter a name (Y/N)? ". Use a "while" loop to accomplish this. As long as the user enters either an upper or lowercase 'Y', then prompt to the screen "Enter First and Last Name: " and then get keyboard input of the name. After entering the name, display the name to the screen.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT