General C++ program help?
-
This below is my assignment (just so you have a reference to what I want my code to do); Write a program to prompt the user for a shape code. Read the shape code from the keyboard. Based on the shape code entered, prompt for the measurement(s) needed to calculate the area for that shape. Read the measurement(s) from the keyboard. Calculate the area of the shape. Print the area on the monitor. Allow the user to continue entering shape codes and values until he/she indicates no more processing is required. When the user does not want to continue, print a closing message. 1. Print an overview of the program's purpose. This should be in terms a user would understand. Make sure this is printed only once per program execution. Place this code in a function and call this function from main. 2. Write at least three other functions which are called from main. Examples of possible functions: get user input, calculate area for a shape, print output. Make at least one function receive an argument or arguments and at least one function return a return value. (It can be the same function.) One function must use a reference argument. Do not use any global variables. 3. Using a while or do-while loop, read the input, calculate the area, and print the output until the user decides to quit. Ask the user after printing the output if he/she wants to continue. After the user indicates he/she wants to quit, print a closing message. Printing the closing message should be in a separate function called from main. 4. Print the valid geometric shape codes as a "menu". Prompt the user for a valid geometric shape. Do not continue the program until a valid value is entered. The program will only calculate area for a square, a circle, or a rectangle. You may use the following codes for the shapes: C for Circle, S for Square, R for Rectangle. Make sure the information the user sees in the prompt explains clearly what the expected values are. Allow the user to enter the code in lower or upper case. That is, both c and C should be acceptable entries for circle. Use symbolic constants for the shape codes. 5. If the user wants the area of a square calculated, prompt for the length of one side. Calculate area with the formula of area = length * length. . If the user wants the area of a circle calculated, prompt for the circle's radius. Calculate area with the formula of area = PI * radius * radius. If the user wants the area of a rectangle calculated, prompt for the rectangle's length and width. Calculate area with the formula of area = length* width. Use a symbolic constant for PI and set its initial value to 3.14159. 6. Print the calculated area to a precision of 2 decimal places. 7. You may not use any global variables except for symbolic constants. Here's my code; #include <cstdlib> #include <iostream> #include <iomanip> using namespace std; void double areasquare(double& length); void double areacircle(double& radius, double& PI); void double arearectangle(double& lengthtwo, double& width); void getUserInput (char& Y); void output(double); void outputelse (); void functionfrommain (); void validshapes (); int main(int argc, char *argv[]) { const double PI = 3.14159; double radius, length, width, lengthtwo; char Y; char S; char C; char R; functionfrommain (); getUserInput(Y); if (Y == 'Y' || Y == 'y'); cin >> Y; do { length = 0; lengthtwo = 0; width = 0; radius = 0; validshapes (); cout << "Enter the proper letter : " << endl; if (S == 'S' || S == 's') { cout << "Enter length of one side of the square : " << endl; cin >> length; cout << setiosflags(ios::fixed) << setprecision(2); cout << areasquare (); } else if (C == 'C' || C =='c') { cout << "Enter the radius of the circle : " << endl; cin >> radius; cout << setiosflags(ios::fixed) << setprecision(2); cout << areacircle (); } else if (R == 'R' || R =='r') { cout << "Enter the length of the rectangle : " << endl; cin >> lengthtwo; cout << "Enter the width of the rectangle : " << endl; cin >> width; cout << setiosflags(ios::fixed) << setprecision(2); cout << arearectangle (); } } while(S == 'S' || S == 's') || (C == 'C' || C =='c') || (R == 'R' || R =='r'); else { outputelse (); } system("PAUSE"); return EXIT_SUCCESS; } void getUserInput (char& Y) { cout << "Enter Y to continue anything else to stop : " << endl; cin >> Y; } . void areasquare (double& length) { length*length } void areacircle (double& radius) { PI*radius*radius } void arearectangle (double& lengthtwo, double& width) { lengthtwo*width } void outputelse () { cout << "Thank you for using the Area Calculator Service." << endl; } void functionfrommain () { cout << "This program the area for a user specified geometric shape. \ You will be asked to enter a code representing the sha
-
Answer:
For starters, don't use variable names like Y,S,C and R. It's too hard to search for names like that. Stripping out the noise, your code looks like this: cout << "Enter the proper letter : " << endl; if (S == 'S' || S == 's') { } else if (C == 'C' || C =='c') { } else if (R == 'R' || R =='r') { } Where in there did C, R or S get assigned a value? They didn't. There needs to be a cin after the 'Enter the proper letter', and that will only go into a single variable. Something like: char answer; ... cin >> answer; if (answer == 'S' || answer == 's') { } else if (answer == 'C' || answer =='c') Etc.
FutureMa... at Yahoo! Answers Visit the source
Related Q & A:
- How Can I use .net dll in C program?Best solution by Stack Overflow
- How to run an executable from within a c program?Best solution by Stack Overflow
- International Baccalaureate program help?Best solution by Yahoo! Answers
- General electric tv help with a Universal remote?Best solution by Yahoo! Answers
- Can anyone help me with this C++ program?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.