Program 2

  • Uploaded by: Adonis Brown
  • 0
  • 0
  • August 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Program 2 as PDF for free.

More details

  • Words: 851
  • Pages: 5
CSCI 229 C++ for Engineers Summer 2007 Program 2 Due date: Tuesday, June 26, 2006; no later than 10:00 p.m. Problem Description Students at a local elementary school that you have been tutoring are having some difficulty with some mathematical concepts they are learning in their math class. You have decided to write a simple computer program that will help with a few of these concepts. Program Directions Write a C++ program that uses the information found in the formula section to help students to practice their math skills. The program must do the following: • Ask the user to input the two numbers. • Ask the user to select the mathematical operator. o Note if the user inputs a real value to use with the modulus operator, alert the user that the real value inputted cannot be used with the modulus operator. • Ask the user for the answer. • Calculate the correct answer using the input of the numbers and the math operator. • Display to the screen the correct answer as calculated by the formula and a statement telling the user if he/she was correct. • Allow the user to continue with the program until he/she no longer wants to continue to use the program. The program should take both upper and lower case input. Formulas +

MATHEMATICAL OPERATORS Addition

-

Subtraction

*

Multiplication

/

Division

%

Modulus

Program Output The program should display the following: • A question asking the user if he/she wants to begin using the program and continue using the program • A menu displaying the operator selection choices • The correct answers as calculated by the formulas • A statement if the answer is correct or incorrect • An alert that the modulus cannot be used with real values. Program Calculations Failure to include the formulas in the program will result in a deduction of points on the assignment. Program Header Information • Name • Program number • Collaboration statement • The answers to the following question: o What is the purpose of the program? o What is the input? (Is there any?) o What is the output? Sample Run Below is a sample run. DO NOT include additional input or output streams in your program.

/* Adonis Brown Program 2 I worked on the assignment by myself and received no additional assistance. 1. The purpose of this program is to accept numbers from the user, then succesfully perform the operation that they have selected upon the numbers. It also allows them to continue as long as they are willing. 2. The inputs are one input to start and continue the program, 2 numbers, and one input for the operator of the user's liking. 3. The outputs are many. The user is asked if they want to begin. The user is then asked for two numbers and their preferred operator. If the user inputs numbers, and the program performs operations upon them, the user is asked to input their answer to the operation. The program then informs the user if they are correct or incorrect. If during the operator selection process the modulous is selected, and either or both of the numbers are real, the computer informs the user of this and requests that the user selects a different number (or numbers) for usage with the modulous. After this, the program continues as usual. */ #include #include <stdlib.h> #include <string> int main() { double num1, num2, u_ans, p_ans = 0; char oper, redo; cout<<"Enter 'Y' if you would like to begin."<<endl; cin>>redo; while ((redo == 'Y')||(redo == 'y')) { cout<<"Please enter 2 numbers: "; cin>>num1>>num2; cout<<endl<<"Please select your mathematical operator."<<endl; cout<<endl<<"+ = Addition"<<endl<<"- = Subtraction"<<endl<< "* = Multiplication"<<endl<<"/ = Division"<<endl <<"% = Modulous Division (Provides the remainder)"<<endl<<endl; cin>>oper; cout<<endl; while (oper == '%') { if ((oper == '%')&&(num1 != int(num1))&&(num2 != int(num2))) { cout<>num1>>num2; }

else if (oper == '%') { if ((oper == '%')&&(num1 != int(num1))) { cout<>num1; break; } if ((oper == '%')&&(num2 != int(num2))) { cout<>num2; break; } } else break; } while ((oper != '+')&&(oper != '-')&&(oper != '/')&&(oper != '*')&&(oper != '%')) { cout<<"Invalid Entry!"<<endl<<"Enter a new operator: "; cin>>oper; } cout<<endl; switch(oper) { case '+': p_ans = num1 + num2; break; case '-': p_ans = num1 - num2; break; case '*': p_ans = num1 * num2; break; case '/': p_ans = num1 / num2; break; case '%': p_ans = int(num1) % int(num2); break; default: cout<<"Invalid Entry!"<<endl; break; } cout<<"Please enter your answer."<<endl<<endl<<"(Your answer)"<<endl<< num1<<" "<>redo; cout<<endl; } system("PAUSE"); return 0; }

Related Documents

Program 2
August 2019 30
Program 2
April 2020 19
Program 2
November 2019 21
Program 2
May 2020 8
2. Program Semester.docx
October 2019 12

More Documents from "Zipora Aliana"

Program 2
August 2019 30
Program 1
July 2019 29
October 2019 48
October 2019 21
Karevane Islam
October 2019 23
October 2019 30