C :: Take Averages Of Whole Week And Output Print Statement
Jul 17, 2013
I wanted to take the averages of the whole week and output a print statement. I've tired few ways this like assigning "temp" a pointer, or in each if statement assigning temp to a new variable like a, b , c etc. Then adding them all up at the end and dividing by 7. My issue is I am unclear how to store the number typed for each if statement while the program is running, then have it compute the simple equation. The code in question is below:
Write a C++ program to output information for three students. The information stored in your program contains student’s first name, middle name, last name, and test score. The following shows the information for the three students, where test score is in the int type.
John Jacob Smith 78 Mary Jane Weems 82 Dave Joe Dale 61
Your program should declare three named string constants for the three students. Each constant contains the student’s first name, middle name, and last name. You may use three int variables to hold values for the three test scores. The first name, middle name, and last name of a student are then extracted using the substr() function shown in class. Your program should also compute the average (in floating-point number format) for the three test scores. The average score computed should be printed to the screen with 2 digits displayed after the decimal point.
The following shows the output from the program. Note that all the output is left-justified with 15 character positions reserved for each.
first name middlename lastname testscore average John Jacob Smith 78 73.67 Mary Jane Weems 82 73.67 Dave Joe Dale 61 73.67
I'm just starting coding and I just want it to input a date, then output a day of the week.
Code: #include <iostream> #include <cmath> using namespace std; int main() { int startday = 0, sm = 1, sd = 1, sy = 2000, cm = 0, cd = 0, cy = 0; cout << "Please enter the current month, day, and year: ";
Prompt the user to enter a day of the week as M (or m), T, W, R, F, S, and U for Monday through Sunday respectively. The user may enter an upper or lower case letter.
When the user enters a character, the program will echo the letter and output the name of the day of the week.
Provide an error trap that reads something like "you have entered an invalid letter; program aborting." Suggestion: use a switch statement with the error trap as the default condition. it is not necessary to prompt for multiple inputs.
So I know how to get the program to echo back the letter and everything. What I am a little confused about is: will I have to define all the letters as their respective day? eg. make M== Monday. And if I do have to do that how would I get it to accept Upper and Lower case letters and recognize that that letter is == monday ect. ect.
Also my main problem is the switch statement as the error trap. I have never used the switch statement, but I know what they do. I just don't really understand how I would use it for an error trap. Am I suppose to just make a case for every other letter in the alphabet other then M T W R F S and U? Even if I do that then what if the user enters a number instead of a letter?
i am trying to write a program to print a statement without spaces in it.For example, if the statement is "Hello, i am Solidsnake", then it should print it as "Hello,iamsolidsnake".
I need to use the output of my IF statement in a calculation. But how can i extract the output from the IF statement in my code?
#include <iostream> #include <cmath> using namespace std; int main(int argc, char *argv[]) { double x, y, z; cout<<"Please enter the student's three test grades:"<<endl; cin>>x>>y>>z;
This is supposed to output t=m and then m is plugged into a function say for -3, plugging it into function f gives 23, well i want 22 blank spaces and then a asterik and go to next line. that is why i put -1 after %'f(m)-1's i
The asterisk appear right next to the t value here but they are way to the right of it when i made this post.
I have an exercise that asks me to print numbers at random from the following set (using only a single statement):
2, 4, 6, 8, 10
Here's my statement:
Code: cout << (2 + rand() % 9) << " ";
which prints numbers at random between 2 and 10, now I can use the modulus operator in an if...else statement to print only even numbers but the exercise specifically requires using only one statement, can that be done using the conditional operator? and if not then how?
I have a question related to switch statement, which the switch in class employee2 gives me error at output. Program compiled well. I am using Code::Block Compiler V10.5. I have created object of class employee2 in main() function to get data from user, store it and display it. At the output, Compiler doesn't show actual output what i am expecting. The fun thing is my compiler printed emocion like (), where (hourly/monthly/weekly) was supposed to print.
Code: #include <iostream> using namespace std; enum period {hourly,weekly,monthly}; class employee2 { private : char ch; period x; double compensation;
Community Hospital needs a program to compute and print a billing statement for each patient. Charges for each day are as follows:
a. room charges: private (P) room = $125.00; semi-private (S) room = $95.00; or ward (W) = $75.00 b. telephone charge = $1.75 c. television charge = $3.50
Write a program to get data from the keyboard, compute the patient’s bill, and print an appropriate statement. Typical input (nut yours do not have to be identical to this) is the following:
How many days was the room occupied? 5 What type of room? P Telephone used during the stay? N Television used during the stay? Y
Keep in mind that the user needs to know that the input can be any integer number of days for the length of stay, either (P, S, or W) for the room type, and either (Y or N) for both telephone and television options.
A statement (which yours MUST be identical to) for the data given follows:
Community Hospital Patient Billing Statement
Number of days in hospital: 5 Type of room: Private Room charge:$ 625.00 Telephone charge:$ 0.00 Television charge:$ 17.50
I am working on a small simple program my program fills up a air plane with customers there is 2 levels 1 and 2 and it will put that person in the spot depending on being picked.
So far i made a boolean airplane with 10 spots I can enter 1 person into the airplane with no problem but then after he sits down i get a infinite loop? I assume i maybe have to use the continue statement I feel like there is something simple that im missing i want to add more people. here is what i have
So when you enter the number 99 its supposed to quit the program and it wasnt so i fixed that then i noticed that if you don't hit the green its supposed to loop back to a certain point but it was going to far back so i put a goto statement in and now it wont output my data table.
Basically I'm supposed to use a while loop to generate a random number and use a switch statement to output the appropriate information. I feel like I'm missing a few things that are very simple.
The errors are: warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data warning C4700: uninitialized local variable 'randomNumber' used
I'm working on a CGI application. I'm trying to test my input with a switch statement and output the result with html tags to populate a web page. From within the switch, I've coded as follows:
HTML Code: switch(mFunc) { case 0: cout << "<p><b>YOU ENTERED THE FOLLOWING TO BE CALCULATED:</b></p>" "<h2>"<< number1 <<"+" << number2 << "</h2>" << endl; break; case 1: cout << "You've entered" << number1 <<"-" << number2 << "to be evaluated" << endl; break;
I know that I'll need to put this in an html body with a content type as such:
At the bottom I have a loop that cout FI,XC,XL,I while going through the loop but when it prints its uneven and setw cant fix it. How do I print values of FI,XC,XL & I to an array so they are aligned.
Finally got to functions. Made a simple one that adds two numbers:
Code: int add(int a, int b){ cout<<"a+b="; return a+b; }
It refuses to give an output unless I use cout.
If I just call the function like so: "add(12, 24);", shouldn't it print out a+b=36? It only prints out "a+b=", unless I use "cout<<" ahead of the call.
My simple question is why does it need cout ahead of the call? Shouldn't "return" do its job and print out the number?
I was recently introduced to the fstream header file. I want to know is their a easy way to print an output with append data in a .txt file.
And secondly I am also having an error with my header file. It says error: cannot open source file "fstring" when I hover my mouse over "#Include<fstring>".
I am using borland turbo c++ version 4.5 and for printing a coloured output i used textcolor() but it is showing error that call the undefined function 'textcolor' in main, so what can i do now to print a coloured output???
I am creating a Matrix class, and one of the constructors parses a string into a matrix. However, printing the result of the constructor (this->Print()) prints what I expect, and an <object_just_created>.Print() call returns bogus data. How is this even possible?
Snippets below:
Matrix::Matrix(const string &str) { // Parse a new matrix from the given string Matrix r = Matrix::Parse(str); nRows= r.nRows; nCols= r.nCols;
[Code] ....
in the driver program, here are the two successive calls
Matrix mm6("[1 2 3.8 4 5; 6 7 8 9 10; 20.4 68.2 1341.2 -15135 -80.9999]"); mm6.Print(); // mm6.Print() calls bogus data, -2.65698e+303 at each location. The matrix's // underlying array is valid, because printing the addresses yields a block // of memory 8 bits apart for each location
I've finally been able to get my coding corrected after doing this for 5 hours and watching numerous tutorials on it... But I now need to create a table. how to create a table with dashed lines like -----------------, both vertical and horizontal.
Another issue I have is that I'm having trouble trying to get a prompt to ask the user how many programs, tests, and quizzes he/she completed with their total points. I got the basic programming done, but need a prompt asking "How many (quizzes, tests, or programs) have you completed?"
Finally, the do-while loop is driving me insane, where I have to set certain values. If it is greater than 2, then I insert formula 1, but if it is less than 2, then I insert formula 2. Whichever way it goes, the total points earned minus the two lowest scores are then calculated into an average.
Code:
#include <iostream> #include <iomanip> #include <string> using namespace std; int main()
[code]....
The whole basis of the program is to calculate the averages of programs, tests, and quizzes done during a semester at a school. The user is asked how many of each category he/she has completed (total points earned and total points possible). All of this is then calculated into a cumulative class average in a table along with points earned and points possible for each category (along with tests and quizzes combined into one average along with individual averages).