Please support our C++ advertiser: Programming Forums
Views: 9849 | Replies: 36
![]() |
•
•
Join Date: Sep 2004
Posts: 15
Reputation:
Rep Power: 5
Solved Threads: 0
Hello everyone, I've been browsing this forum for small while and have gotten some great information out of it through searching so I thank you very much for that.
Currently though I have a C++ program I have to write for class that inputs the full name of the student, then it asks for their lab point, their homework points and their test points.
I'm going to make it out of a hundred, so I'll have the lab worth 35 points, hw worth 15 points, and test worth 50 points.
Then it has to take the total value and give it a letter grade based on these requirements:
100-80 A
79 - 50 B
49 - 45 C
44 and below F
Here is what I have so far, I've got the total grade in and the name input(except the last name doesn't show for some reason) so now I just have to get the program to spit out a letter grade using if else statements. Need help ASAP!!!! this is due in an hour
#include <iostream>
float lab, homework, test, total;
char line[75];
main()
{
cout<< "Enter Students' lab points from 0-35 "<< "\n";
cin>> lab;
cout<< "Enter Students' homework points from 0-15 "<< "\n";
cin>> homework;
cout<< "Enter Students' test points from 0-50 "<< "\n";
cin>> test;
total = lab + homework + test;
cout<< "Enter students' full name: "<< "\n";
cin>> line;
cout<< "Students' name is "<< line << "\n";
cout<< "Final grade is "<< total << "\n";
return(0);
}
Currently though I have a C++ program I have to write for class that inputs the full name of the student, then it asks for their lab point, their homework points and their test points.
I'm going to make it out of a hundred, so I'll have the lab worth 35 points, hw worth 15 points, and test worth 50 points.
Then it has to take the total value and give it a letter grade based on these requirements:
100-80 A
79 - 50 B
49 - 45 C
44 and below F
Here is what I have so far, I've got the total grade in and the name input(except the last name doesn't show for some reason) so now I just have to get the program to spit out a letter grade using if else statements. Need help ASAP!!!! this is due in an hour

#include <iostream>
float lab, homework, test, total;
char line[75];
main()
{
cout<< "Enter Students' lab points from 0-35 "<< "\n";
cin>> lab;
cout<< "Enter Students' homework points from 0-15 "<< "\n";
cin>> homework;
cout<< "Enter Students' test points from 0-50 "<< "\n";
cin>> test;
total = lab + homework + test;
cout<< "Enter students' full name: "<< "\n";
cin>> line;
cout<< "Students' name is "<< line << "\n";
cout<< "Final grade is "<< total << "\n";
return(0);
}
•
•
Join Date: Sep 2004
Location: Overflow State
Posts: 183
Reputation:
Rep Power: 5
Solved Threads: 4
Greetings,
The if-else statement is normally used to express decisions, where the else part is usually optional. Since an if simply tests the numeric value of an expression, coding shortcuts are possible:
Example 1.1: Using coding shortcuts
There is an ambiguity when an else is omitted from a nested if sequence, since the else part of an if-else is optional.
Example 1.2: Ambiguity between control flow statements
The construction of the if-else syntax is simple:
The else-if construction is similar, though it evaluates all expressions in order; and if any expression is true, the statement associated with it is executed and terminates the whole chain:
Example 1.3: Using the Else-If syntax
So to do accomplish your task, you could do something like the following:
Code 1.1: Using if-else in application
If you have multiple statements withing one if, you must group the declarations together into a compund statement using braces ({ }):
Example 1.4: Grouping declarations
I hope this helps, and if you have any further questions please feel free to ask.
- Stack Overflow
The if-else statement is normally used to express decisions, where the else part is usually optional. Since an if simply tests the numeric value of an expression, coding shortcuts are possible:
if (expression) // instead of if (expression != 0)
There is an ambiguity when an else is omitted from a nested if sequence, since the else part of an if-else is optional.
if (a < 0) if (b < c) r = b; else r = c;
The construction of the if-else syntax is simple:
if (expression) statement 1 else statement 2
The else-if construction is similar, though it evaluates all expressions in order; and if any expression is true, the statement associated with it is executed and terminates the whole chain:
if (expression) statment else if (expression) statement else if (expression) statement else statement
So to do accomplish your task, you could do something like the following:
if (total >= 80 && total <= 100) // 80 between 100 statement; else if (total >= 50 && total <= 79) // 50 between 79 statement; else if (total >= 45 && total <= 49) // 45 between 49 statement; else // probably an F grade here statement;
If you have multiple statements withing one if, you must group the declarations together into a compund statement using braces ({ }):
if (expression) { // multi-computation statement 1; statement 2; }else // single computation statement 3;
I hope this helps, and if you have any further questions please feel free to ask.
- Stack Overflow
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.
IRC
Channel: irc.daniweb.com
Room: #c, #shell
IRC
Channel: irc.daniweb.com
Room: #c, #shell
•
•
Join Date: Sep 2004
Posts: 15
Reputation:
Rep Power: 5
Solved Threads: 0
Thanks a BUNCH stack.
That was a great explaination and I'm glad to be welcomed like that, you don't normally see someone help a new person (or at least put in that much effort).
I'm on my second assignment now which I have to write a program that will ask the user for one of three choices.
for example:
Press c to calculate the area of a circle, t for a triangle, r for a rectangle, or q for quit.
Then the program comes and asks if you typed in c
"What is the radius of the circle?"
you input the radius then it spits out the area of the circle then loops back to the main question until you hit q to quit. I have the concept down of what I want to do with it but I know there is more to it. Here is what I've got so far.
#include<iostream>
using namespace std;
float answer;
int main()
{
char shape;
double height, width, base, radius;
cout<< "Press r for rectangle, t for triangle, or c for circle " << "\n";
cin>> shape;
if(shape=='r'||shape=='R')
{
double height, width, answer;
cout<< "Enter the Height:";
cin>> height;
cout<< "Enter the Width:";
cin>> width;
answer = height * width;
cout<< "The area is: " << answer << "\n";
}
elseif(shape=='t'||shape=='T')
{
double height, base;
cout<< "Enter the height:";
cin>> height;
cout<< "Enter the base length:";
cin>> base;
answer = base * height * .5;
cout<< "The area is: " << answer << "\n";
}
elseif(shape=='c'||shape='C')
{
double radius;
cout<< "Enter the Radius:";
cin>> radius;
answer = radius * 3.1419;
cout<< The area is: " << answer << "\n";
}
return(0)
}
// I'm sick of trying to figure this out
Thanks for any help you can give.
That was a great explaination and I'm glad to be welcomed like that, you don't normally see someone help a new person (or at least put in that much effort).
I'm on my second assignment now which I have to write a program that will ask the user for one of three choices.
for example:
Press c to calculate the area of a circle, t for a triangle, r for a rectangle, or q for quit.
Then the program comes and asks if you typed in c
"What is the radius of the circle?"
you input the radius then it spits out the area of the circle then loops back to the main question until you hit q to quit. I have the concept down of what I want to do with it but I know there is more to it. Here is what I've got so far.
#include<iostream>
using namespace std;
float answer;
int main()
{
char shape;
double height, width, base, radius;
cout<< "Press r for rectangle, t for triangle, or c for circle " << "\n";
cin>> shape;
if(shape=='r'||shape=='R')
{
double height, width, answer;
cout<< "Enter the Height:";
cin>> height;
cout<< "Enter the Width:";
cin>> width;
answer = height * width;
cout<< "The area is: " << answer << "\n";
}
elseif(shape=='t'||shape=='T')
{
double height, base;
cout<< "Enter the height:";
cin>> height;
cout<< "Enter the base length:";
cin>> base;
answer = base * height * .5;
cout<< "The area is: " << answer << "\n";
}
elseif(shape=='c'||shape='C')
{
double radius;
cout<< "Enter the Radius:";
cin>> radius;
answer = radius * 3.1419;
cout<< The area is: " << answer << "\n";
}
return(0)
}
// I'm sick of trying to figure this out

Thanks for any help you can give.
•
•
•
•
Originally Posted by sid3ways s13
I'm on my second assignment now which I have to write a program that will ask the user for one of three choices.
for example:
Press c to calculate the area of a circle, t for a triangle, r for a rectangle, or q for quit.
Then the program comes and asks if you typed in c
"What is the radius of the circle?"
you input the radius then it spits out the area of the circle then loops back to the main question until you hit q to quit. I have the concept down of what I want to do with it but I know there is more to it. Here is what I've got so far.
#include<iostream>
using namespace std;
float answer;
int main()
{
for(;;)
{
char shape;
double height, width, base, radius;
cout<< "Press r for rectangle, t for triangle, or c for circle, q to quit\n";
cin>> shape;
if(shape == 'q' || shape == 'Q')
{
break;
}
else if ( shape=='r'||shape=='R' )
{
double height, width, answer;
cout<< "Enter the Height:";
cin>> height;
cout<< "Enter the Width:";
cin>> width;
answer = height * width;
cout<< "The area is: " << answer << "\n";
}
else if(shape=='t'||shape=='T')
{
double height, base;
cout<< "Enter the height:";
cin>> height;
cout<< "Enter the base length:";
cin>> base;
answer = base * height * .5;
cout<< "The area is: " << answer << "\n";
}
else if(shape=='c'||shape=='C')
{
double radius;
cout<< "Enter the Radius:";
cin>> radius;
answer = radius * 3.1419;
cout<< "The area is: " << answer << "\n";
}
}
return 0;
}
/* my output
Press r for rectangle, t for triangle, or c for circle, q to quit
r
Enter the Height:2
Enter the Width:4
The area is: 8
Press r for rectangle, t for triangle, or c for circle, q to quit
c
Enter the Radius:6
The area is: 18.8514
Press r for rectangle, t for triangle, or c for circle, q to quit
t
Enter the height:2
Enter the base length:9
The area is: 9
Press r for rectangle, t for triangle, or c for circle, q to quit
q
*/
High Plains Blogger #plains #lounge ## I, for one, welcome our new socialist overlords.
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
•
•
Join Date: Sep 2004
Location: Overflow State
Posts: 183
Reputation:
Rep Power: 5
Solved Threads: 4
•
•
•
•
Originally Posted by sid3ways s13
Thanks a BUNCH stack.
That was a great explaination and I'm glad to be welcomed like that, you don't normally see someone help a new person (or at least put in that much effort).
•
•
•
•
Originally Posted by sid3ways s13
I'm on my second assignment now which I have to write a program that will ask the user for one of three choices... Here is what I've got so far.
Firstly, lets look at our else-if calls. In your example, you may receive undeclared identifier errors because the call else and if are two different expression decisions, though are in construction with each other:
// Your approach elseif(shape... // Correct approach else if(shape...
The last cout also has an error:
cout<< The area is: " << answer << "\n";
cout<< "The area is: " << answer << "\n";
return(0);
else if(shape=='c'||shape='C')
else if(shape=='c'||shape=='C')Hope this helps,
- Stack Overflow
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.
IRC
Channel: irc.daniweb.com
Room: #c, #shell
IRC
Channel: irc.daniweb.com
Room: #c, #shell
•
•
Join Date: Sep 2004
Posts: 15
Reputation:
Rep Power: 5
Solved Threads: 0
Wow, I'm simply amazed by the help you get on here. I should be paying you guys the 9k a year to teach me this stuff instead of some teacher than I've honestly learned VERY little from. I'm pretty much doing this all on my own.
I'll be writing all of my programs and coming on here to let me know what I'm doing wrong and I can gaurantee I'll learn the coding process much faster than sitting in class.
Do you guys also mind if I email my finished hw to you to at least check over?
Thanks so much again guys!
Andy
I'll be writing all of my programs and coming on here to let me know what I'm doing wrong and I can gaurantee I'll learn the coding process much faster than sitting in class.
Do you guys also mind if I email my finished hw to you to at least check over?
Thanks so much again guys!
Andy
•
•
•
•
Originally Posted by sid3ways s13
Do you guys also mind if I email my finished hw to you to at least check over?
High Plains Blogger #plains #lounge ## I, for one, welcome our new socialist overlords.
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
•
•
Join Date: Sep 2004
Posts: 42
Reputation:
Rep Power: 5
Solved Threads: 0
hey, I could use a little help too. I need to write a program that asks for a series of integers one at a time. when 0 is entered I need to make the program display the following: the number of ints entered. The average of them. the largest and smallest ones. and the difference between the largest and smallest. The area that I need help with the most would be finding the number of integers entered.
thanx
thanx
•
•
•
•
Originally Posted by the b
hey, I could use a little help too.
•
•
•
•
Originally Posted by the b
I need to write a program that asks for a series of integers one at a time. when 0 is entered I need to make the program display the following: the number of ints entered. The average of them. the largest and smallest ones. and the difference between the largest and smallest.
•
•
•
•
Originally Posted by the b
The area that I need help with the most would be finding the number of integers entered.
High Plains Blogger #plains #lounge ## I, for one, welcome our new socialist overlords.
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode