Help with a project due tommorow

Hello. I am new to programming and cant seem to figure out this project. i need to have the program end if 2 invalid inputs ( valid is 0.00 - 100.00)are entered for the same variable. it will also need to display a warning after the first invalid input is entered and returns so that the user can place the second input, and display text after the 2nd invalid input and will end the program.

If you want the actual word document let me know and i can get it to you.

Here is the project details

Problem: DESIGN and COMPLETE a program ACCORDINGLY that determines final letter grade for a student with encouraging comment. Three exams and two assignment scores as well as the student name will be entered by the user. Every score should range from 0.00 – 100.00. The program will give user only one chance to correct invalid score and provide meaningful feedback. Exams and assignments have equal weights for the final score (i.e. 50% by each category) that determines the final grade.

i trimmed the code i have so far. if you need all the code then let me know.


#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main ()
{
float exam_1;
float exam_2;
float exam_3;
float assignment_1;
float assignment_2;
float weighted_exam = .1667;
float weighted_assignment = .25;
string name;

cout << "Please enter student name <First Last>: "; // this will ask for the students first and last name
getline(cin, name);

cout << "\n";

cout << "\t Be sure to include the decimal point for scores.\n";

cout <<"\t !!! All scores should range from 0.00 to 100.00!!! \n";

cout << "\t For example: 80.50 \n";

cout << "\n";

cout << "Please enter your exam 1 score: ";
cin >> exam_1;

cout << "Please enter your exam 2 score: ";
cin >> exam_2;

cout << "Please enter your exam 3 score: ";
cin >> exam_3;

cout << "Please enter your assignment 1 score: ";
cin >> assignment_1;

cout << "Please enter your assignment 2 score: ";
cin >> assignment_2;

cout << endl;

cout << "-" << "OUTPUT" << "-\n";

the code would continue from here
Last edited on
Ok, what do you need to do?
It is not clear.
i need to have the program end if 2 invalid inputs ( valid is 0.00 - 100.00)are entered for the same variable. it will also need to display a warning after the first invalid input is entered and returns so that the user can place the second input, and display text after the 2nd invalid input and will end the program.


Put it in a function.
1
2
3
4
5
6
7
8
9
10
11
12
// Print the prompt and get a value. Make sure it's between 0 and 100
// (inclusive).  If there's a problem then try one more time. On success,
// return true and set val. On failure, return false and val is undefined.
bool getPercent(const char *prompt, double &val)
{
    for (int i=0; i<2; ++i) {
        cout << prompt << ' ';
        if (cin >> val &&
            val >= 0.0 && val <= 100.0) return true;
    }
    return false;
}

Hello.

did you finish this project? I'm in the same boat and my due is tomorrow. would you please share your codes so I have an example to work with?
Topic archived. No new replies allowed.