#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout << "Enter the score for test #1:" << endl;
cin >> a;
cout << "Enter the score for test #2:"<< endl;
cin >> b;
cout << "Enter the score for test #3:" << endl;
cin >> c;
cout << "First test:" << a << endl;
cout << "Second test:" << b << endl;
cout << "Third test:" << c << endl;
if ( )
{
cout << " After dropping test #2, the points earned are" << << /
cout << "The letter grade is
return 0;
}
11 Replies - 259 Views - Last Post: 04 October 2012 - 12:36 AM
#1
How to drop the lowest number of 3 and display out put
Posted 03 October 2012 - 09:58 PM
Replies To: How to drop the lowest number of 3 and display out put
#2
Re: How to drop the lowest number of 3 and display out put
Posted 03 October 2012 - 10:04 PM
osu1, on 04 October 2012 - 10:28 AM, said:
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout << "Enter the score for test #1:" << endl;
cin >> a;
cout << "Enter the score for test #2:"<< endl;
cin >> b;
cout << "Enter the score for test #3:" << endl;
cin >> c;
cout << "First test:" << a << endl;
cout << "Second test:" << b << endl;
cout << "Third test:" << c << endl;
if ( )
{
cout << " After dropping test #2, the points earned are" << << /
cout << "The letter grade is
return 0;
}
You need a series of if conditions to make the lowest number get dropped. After that you can add the other 2 variables.
eg.
if(a<b && a<c)
{
int result = b+c;
}
else if ( b<a && b<c)
{
int result = a+c;
}
else
{
int result= a+b;
}
regards,
Raghav
This post has been edited by raghav.naganathan: 03 October 2012 - 10:28 PM
#3
Re: How to drop the lowest number of 3 and display out put
Posted 03 October 2012 - 10:14 PM
raghav.naganathan, on 03 October 2012 - 10:04 PM, said:
osu1, on 04 October 2012 - 10:28 AM, said:
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout << "Enter the score for test #1:" << endl;
cin >> a;
cout << "Enter the score for test #2:"<< endl;
cin >> b;
cout << "Enter the score for test #3:" << endl;
cin >> c;
cout << "First test:" << a << endl;
cout << "Second test:" << b << endl;
cout << "Third test:" << c << endl;
if ( )
{
cout << " After dropping test #2, the points earned are" << << /
cout << "The letter grade is
return 0;
}
You need a series of if conditions to make the lowest number get dropped. After that you can add the other 2 variables.
eg.
if(a<b && a<c)
{
int result = b+c;
}
else if ( b<a && b<c)
{
int result = a+c;
}
else
{
int result= a+c;
}
regards,
Raghav
Ah I see thank you but say after I drop the lowest one, and then i want to classify them like say a+b = 80 is a B grade , and 90 is an A , is this more if/else statements inside of the else statemetns already there?
This post has been edited by osu1: 03 October 2012 - 10:16 PM
#4
Re: How to drop the lowest number of 3 and display out put
Posted 03 October 2012 - 10:20 PM
switch (result)
{
case >= 90
//return 'A'
break;
case >= 80
//return 'B'
break;
}
This post has been edited by DimitriV: 03 October 2012 - 10:21 PM
#5
Re: How to drop the lowest number of 3 and display out put
Posted 03 October 2012 - 10:25 PM
DimitriV, on 03 October 2012 - 10:20 PM, said:
switch (result)
{
case >= 90
//return 'A'
break;
case >= 80
//return 'B'
break;
}
We have not gotten to switch statements yet so I cant use that. Thank you though.
This post has been edited by osu1: 03 October 2012 - 10:25 PM
#6
Re: How to drop the lowest number of 3 and display out put
Posted 03 October 2012 - 10:32 PM
#7
Re: How to drop the lowest number of 3 and display out put
Posted 03 October 2012 - 10:41 PM
raghav.naganathan, on 03 October 2012 - 10:32 PM, said:
Thank you and one last question, I have to repeat this A , B, C grade if/else statements for every drop the lowest grade if/else statements correct?
#8
Re: How to drop the lowest number of 3 and display out put
Posted 03 October 2012 - 10:49 PM
Lab4_Ex2.cpp:32: error: expected primary-expression before '>=' token
Lab4_Ex2.cpp:36: error: expected primary-expression before '>=' token
Lab4_Ex2.cpp:49: error: expected `(' before '<' token
Lab4_Ex2.cpp:99: error: expected `}' at end of input
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout << "Enter the score for test #1:" << endl;
cin >> a;
cout << "Enter the score for test #2:"<< endl;
cin >> b;
cout << "Enter the score for test #3:" << endl;
cin >> c;
cout << "First test:" << a << endl;
cout << "Second test:" << b << endl;
cout << "Third test:" << c << endl;
if (a<b && a<c )
{
int result = b+c;
if ( result >= 92)
{
cout << " Your grade is an a" << endl;
}
else if ( result < 92 || >= 82 )
{
cout << " Your grade is a b"<< endl;
}
else if ( result < 82 || >= 72)
{
cout << "Your grade is a c" << endl;
}
else if ( result < 72)
{
cout << "Your grade is a d" << endl;
}
}
else if <b , a && b < c)
{
int result = a + c;
if ( result >= 92)
{
cout << " Your grade is an a" << endl;
}
else if ( result < 92 || >= 82 )
{
cout << " Your grade is a b"<< endl;
}
else if ( result < 82 || >= 72)
{
cout << "Your grade is a c" << endl;
}
else if ( result < 72)
{
cout << "Your grade is a d" << endl;
}
}
else
{
int result = a + c;
if ( result >= 92)
{
cout << " Your grade is an a" << endl;
}
else if ( result < 92 || >= 82 )
{
cout << " Your grade is a b"<< endl;
}
else if ( result < 82 || >= 72)
{
cout << "Your grade is a c" << endl;
}
else if ( result < 72)
{
cout << "Your grade is a d" << endl;
}
}
return 0;
}
#9
Re: How to drop the lowest number of 3 and display out put
Posted 03 October 2012 - 10:59 PM
osu1, on 04 October 2012 - 11:19 AM, said:
Lab4_Ex2.cpp:32: error: expected primary-expression before '>=' token
Lab4_Ex2.cpp:36: error: expected primary-expression before '>=' token
Lab4_Ex2.cpp:49: error: expected `(' before '<' token
Lab4_Ex2.cpp:99: error: expected `}' at end of input
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout << "Enter the score for test #1:" << endl;
cin >> a;
cout << "Enter the score for test #2:"<< endl;
cin >> b;
cout << "Enter the score for test #3:" << endl;
cin >> c;
cout << "First test:" << a << endl;
cout << "Second test:" << b << endl;
cout << "Third test:" << c << endl;
if (a<b && a<c )
{
int result = b+c;
if ( result >= 92)
{
cout << " Your grade is an a" << endl;
}
else if ( result < 92 || >= 82 )
{
cout << " Your grade is a b"<< endl;
}
else if ( result < 82 || >= 72)
{
cout << "Your grade is a c" << endl;
}
else if ( result < 72)
{
cout << "Your grade is a d" << endl;
}
}
else if <b , a && b < c)
{
int result = a + c;
if ( result >= 92)
{
cout << " Your grade is an a" << endl;
}
else if ( result < 92 || >= 82 )
{
cout << " Your grade is a b"<< endl;
}
else if ( result < 82 || >= 72)
{
cout << "Your grade is a c" << endl;
}
else if ( result < 72)
{
cout << "Your grade is a d" << endl;
}
}
else
{
int result = a + c;
if ( result >= 92)
{
cout << " Your grade is an a" << endl;
}
else if ( result < 92 || >= 82 )
{
cout << " Your grade is a b"<< endl;
}
else if ( result < 82 || >= 72)
{
cout << "Your grade is a c" << endl;
}
else if ( result < 72)
{
cout << "Your grade is a d" << endl;
}
}
return 0;
}
That was not what I meant. Let the if statements for finding out result be independent.They will help you to remove the lowest value and will calculate the result i.e the sum of the 2 higher values.
once that is finished, you will want to print the grade. For that you should use separate if-else if conditions.
Please do not nest the if statements as you have done.
let them be separate like this.
if(result>=90) cout<<"Grade A"; else if(result>=80) cout<<"Grade B"; else if(result>=70) cout<<"Grade C"; else cout<<"Grade D";
regards,
Raghav
#10
Re: How to drop the lowest number of 3 and display out put
Posted 03 October 2012 - 11:39 PM
#11
Re: How to drop the lowest number of 3 and display out put
Posted 04 October 2012 - 12:17 AM
raghav.naganathan, on 03 October 2012 - 10:59 PM, said:
osu1, on 04 October 2012 - 11:19 AM, said:
Lab4_Ex2.cpp:32: error: expected primary-expression before '>=' token
Lab4_Ex2.cpp:36: error: expected primary-expression before '>=' token
Lab4_Ex2.cpp:49: error: expected `(' before '<' token
Lab4_Ex2.cpp:99: error: expected `}' at end of input
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout << "Enter the score for test #1:" << endl;
cin >> a;
cout << "Enter the score for test #2:"<< endl;
cin >> b;
cout << "Enter the score for test #3:" << endl;
cin >> c;
cout << "First test:" << a << endl;
cout << "Second test:" << b << endl;
cout << "Third test:" << c << endl;
if (a<b && a<c )
{
int result = b+c;
if ( result >= 92)
{
cout << " Your grade is an a" << endl;
}
else if ( result < 92 || >= 82 )
{
cout << " Your grade is a b"<< endl;
}
else if ( result < 82 || >= 72)
{
cout << "Your grade is a c" << endl;
}
else if ( result < 72)
{
cout << "Your grade is a d" << endl;
}
}
else if <b , a && b < c)
{
int result = a + c;
if ( result >= 92)
{
cout << " Your grade is an a" << endl;
}
else if ( result < 92 || >= 82 )
{
cout << " Your grade is a b"<< endl;
}
else if ( result < 82 || >= 72)
{
cout << "Your grade is a c" << endl;
}
else if ( result < 72)
{
cout << "Your grade is a d" << endl;
}
}
else
{
int result = a + c;
if ( result >= 92)
{
cout << " Your grade is an a" << endl;
}
else if ( result < 92 || >= 82 )
{
cout << " Your grade is a b"<< endl;
}
else if ( result < 82 || >= 72)
{
cout << "Your grade is a c" << endl;
}
else if ( result < 72)
{
cout << "Your grade is a d" << endl;
}
}
return 0;
}
That was not what I meant. Let the if statements for finding out result be independent.They will help you to remove the lowest value and will calculate the result i.e the sum of the 2 higher values.
once that is finished, you will want to print the grade. For that you should use separate if-else if conditions.
Please do not nest the if statements as you have done.
let them be separate like this.
if(result>=90) cout<<"Grade A"; else if(result>=80) cout<<"Grade B"; else if(result>=70) cout<<"Grade C"; else cout<<"Grade D";
regards,
Raghav
I took off the nested statements but still cannot get it to work, it doesnt even get to my if statements at all. Just displays the numbers I inputed.
#12
Re: How to drop the lowest number of 3 and display out put
Posted 04 October 2012 - 12:36 AM
|
|

New Topic/Question
Reply



MultiQuote



|