If statement problem

closed account (LE8p216C)
I keep getting errors for <= which I don't understand and also error for all the if statements expecting an expression. Will post my code first not done but its basically what I need to just rewash and redo for the next two students.
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
unsigned
studentid{},
firsttest{},
secondtest{},
lab1{},
lab2{},
lab3{},
lab4{},
average{};
{
cout << "Enter student id, followed by test 1, test2, lab1, lab2, lab3, and lab4" << endl;
cin >> studentid >> firsttest >> secondtest >> lab1 >> lab2 >> lab3 >> lab4;
if (firsttest < 0 || firsttest >= 100 || secondtest < 0 || secondtest >= 100)
{
cout << "Your test score must be a valid percentage score between 0 and 100";
cout << "Enter student id, followed by test 1, test2, lab1, lab2, lab3, and lab4";
cin >> studentid >> firsttest >> secondtest >> lab1 >> lab2 >> lab3 >> lab4;
average = firsttest + secondtest + lab1 + lab2 + lab3 + lab4;
cout << average;
{
if (average >= 90 && <= 100)
cout << "You got an A average\n";
if (average >= 80 && <= 89.9)
cout << "You got an B average\n";
if (average >= 70 && <= 79.9)
cout << "You got an C average\n";
if (average >= 60 && <= 69.9)
cout << "You got an D average\n";
if (average >= 0 && <= 59.9)
cout << "You got an F average\n";

}
}
}
}

I need help calculating the final grades. Assume we have only 3 students in this class so build a loop into this program. Obtain the student id #, the first test grade, second test score and 4 lab assignment scores from the keyboard. Validate that the 2 test scores are between 0-100. In the main routine, calculate the average by adding the six scores together and then dividing the result by six. Call a function, taking with you the average, that will figure and print the letter grade
QUIT spamming with new posts for the same problem!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
    unsigned
    studentid{},
    firsttest{},
    secondtest{},
    lab1{},
    lab2{},
    lab3{},
    lab4{};
    double average{};
    //{
    cout << "Enter student id, followed by test 1, test2, lab1, lab2, lab3, and lab4" << endl;
    cin >> studentid >> firsttest >> secondtest >> lab1 >> lab2 >> lab3 >> lab4;
    if (firsttest > 0 and  firsttest < 100 and secondtest > 0 and secondtest < 100)
    {
        //            cout << "Enter student id, followed by test 1, test2, lab1, lab2, lab3, and lab4";
        //            cin >> studentid >> firsttest >> secondtest >> lab1 >> lab2 >> lab3 >> lab4;
        average = (firsttest + secondtest + lab1 + lab2 + lab3 + lab4)/6.0;
        cout << average;
        //{
        if (average >= 90 && average <= 100)
            cout << "You got an A average\n";
        else if (average >= 80 && average <= 89.9)
            cout << "You got an B average\n";
        else if (average >= 70 && average <= 79.9)
            cout << "You got an C average\n";
        else if (average >= 60 && average <= 69.9)
            cout << "You got an D average\n";
        else if (average >= 0 && average <= 59.9)
            cout << "You got an F average\n";
    }
    else
    {
        cout << "Your test score must be a valid percentage score between 0 and 100";
    }
    
    return 0;
}
closed account (LE8p216C)
Thanks man I'm picking up on it slowly but knew I was close is there a way to run a loop 3 times with that or just repaste the code part to ask 3 times?
Green tick your other thread on this first!
closed account (LE8p216C)
Just did that sorry about that btw!
PS Why not try both ways of doing it - loop, or cut and paste?
closed account (LE8p216C)
I did the copy and paste to use for three students its just very long and still learning on what command would ask it three times
What's wrong with a loop? Especially useful if you had, say, 1000 to enter.

1
2
3
4
5
6
for(int student_count = 0; student_count < 3; student_count++)
{
    // do the same stuff
    
    student_count++;
}


This would print out the results but doesn't store individual scores - how to do that comes later.


This time show us your code. Otherwise ... :(


closed account (LE8p216C)
againtry solved that one I am almost done with my other one have one problem not sure how to fix this problem. I have it saying in program if stuff happens then mild = largest but im getting an error obviously cause largest isn't a value I want the program to know its the word "largest" value any idea?// Austin West 4/29/2020 This program is used to help a company keep track of their chips and salsa sales.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
float
Mild,
Medium,
Sweet,
Hot,
Zesty,
Total,
Largest,
Smallest,
Average;
cout << "Enter the number of Mild salsa sold ";
cin >> Mild;
cout << "Enter the number of Medium salsa sold ";
cin >> Medium;
cout << "Enter the number of Sweet salsa sold ";
cin >> Sweet;
cout << "Enter the number of Hot salsa sold ";
cin >> Hot;
cout << "Enter the number of Zesty salsa sold ";
cin >> Zesty;
Total = Mild + Medium + Sweet + Hot + Zesty;
Average = Total / 5;
{
if (Mild > Medium || Sweet || Hot || Zesty);
cin >> (Mild = Largest);
if (Medium > Mild || Sweet || Hot || Zesty);
cin >> (Medium = Largest);
if (Sweet > Medium || Mild || Hot || Zesty);
cin >> (Sweet = Largest);
if (Hot > Medium || Sweet || Mild || Zesty);
cin >> (Hot = Largest);
if (Zesty > Medium || Sweet || Hot || Mild);
cin >> (Zesty = Largest);
{
if (Mild < Medium || Sweet || Hot || Zesty);
cin >> (Mild = Smallest);
if (Medium < Mild || Sweet || Hot || Zesty);
cin >> (Medium = Smallest);
if (Sweet < Medium || Mild || Hot || Zesty);
cin >> (Sweet = Smallest);
if (Hot < Medium || Sweet || Mild || Zesty);
cin >> (Hot = Smallest);
if (Zesty < Medium || Sweet || Hot || Mild);
cin >> (Zesty = Smallest);
cout << Total << Average << Largest << Smallest;
}
}
}


For a start, lines like the following do nothing other than perform the test, and nothing more because of the ';'

if (Hot < Medium || Sweet || Mild || Zesty);
Here's also a start on how to do this with functions.

You stiil need a function to check each input value, smallest and largest.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <iomanip>

using namespace std;

int total(int a, int b, int c, int d , int e)
{
    return a+b+c+d;
}

float average(int a, int b, int c, int d , int e)
{
    return total(a, b, c, d, e)/5.0;
}


int smallest(int a, int b, int c, int d , int e)
{
    // ???
    // return ???;
}

int largest(int a, int b, int c, int d , int e)
{
    // ???
    // return ???;
}

int main()
{
    int
    Mild,
    Medium,
    Sweet,
    Hot,
    Zesty;
    
    cout << "Enter the number of Mild salsa sold ";
    cin >> Mild;
    cout << "Enter the number of Medium salsa sold ";
    cin >> Medium;
    cout << "Enter the number of Sweet salsa sold ";
    cin >> Sweet;
    cout << "Enter the number of Hot salsa sold ";
    cin >> Hot;
    cout << "Enter the number of Zesty salsa sold ";
    cin >> Zesty;
    
    
    
    cout << "Total jars: " << total(Mild, Medium, Sweet, Hot, Zesty) << endl;
    cout << "Average jars: " << average(Mild, Medium, Sweet, Hot, Zesty) << endl;
    
    
    return 0;
}


Hint: to get the smallest number take the first as the smallest and if the next one is smaller then that one becomes the smallest then go through the series ...
Topic archived. No new replies allowed.