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.
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...
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.
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:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT