Connecting...

This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of Introduction to C++
For more information, please see full course syllabus of Introduction to C++
Introduction to C++ Branching
Lecture Description
In this lesson, our instructor Alvin Sylvain gives an introduction to branching. He starts by explaining code blocks and scope. Then, he gets into 'if,' 'else,' 'conditional' and 'switch' statements. He ends with do's and don'ts.
Bookmark & Share
Embed
Share this knowledge with your friends!
Copy & Paste this embed code into your website’s HTML
Please ensure that your website editor is in text mode when you paste the code.(In Wordpress, the mode button is on the top right corner.)
×
Since this lesson is not free, only the preview will appear on your website.
- - Allow users to view the embedded video in full-size.
Next Lecture
Previous Lecture
1 answer
Sat Sep 26, 2015 4:57 PM
Post by Donald Sullenger on September 26, 2015
I can't come up with a valid solution to homework number 3. The initial code (in number 2) worked as intended but I get an error when I add in the statement providing an invalid grade when < 0 or > 100. I've also tried breaking that line into "if (rawGrade < 0 or > 100) {" and
"if (rawGrade < 0) or (rawGrade > 100) {" but I always get an error that it doesn't like the "or" (even if I use the || instead of the word). Why?
#include "stdafx.h"
#include <iostream>
using namespace std;
int main ()
{
cout << "Welcome to the Easy Going University Grade System!" << endl;
cout << "Please enter the student's raw grade: " ;
int rawGrade;
cin >> rawGrade;
if (rawGrade < 0 or rawGrade > 100) {
cout << "Invalid grade!";
}
if (rawGrade > 60) {
cout << "You passed!" << endl;}
else {
int curve = (rawGrade * .5); // Determine amount of curve (50% of raw grade)
int curvedGrade = rawGrade + curve; // add curve to initial grade
cout << "The grade is curved by " << curve << " points." << endl;
cout << "Your total grade is " << curvedGrade << "." << endl;
if (curvedGrade <= 60) {
cout << "You failed! No refunds!" << endl; }
else {
cout << "You passed!" << endl; }}
return 0;
}
2 answers
Last reply by: Mark Alvarado
Sat Feb 9, 2013 9:25 PM
Post by Jorge Guerrero on June 27, 2012
17 * 5 whatever that adds up to I'm not gonna work it out???? Jesus! What Master's Degree Professional doesn't know this right off the top of their head? It's 85! I'm sorry, educator.com, but I was cracking when I heard this.
This is the reason I think programming should be taught in schools as a shop elective where you can apply it to another field. No disrespect to programming majors, but if we teach our young students from grade school the basics, then have them keep on the course of taking programming as an elective, they'll become great programmers and professionals by the time they graduate college! Then they can go to grad school in any field of their choosing with this powerful skill: programming.
3 answers
Last reply by: Samuel Bass
Thu May 16, 2013 5:56 PM
Post by kristof anderson on June 14, 2012
where can i get the slide for the classes?