A Demonstration of Branching Based On Relational Operators

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

A demonstration of branching based on relational operators.

#include <iostream.h> 4: int main() 5: { 6: int RedSoxScore, YankeesScore; 7: cout << "Enter the score for the Red Sox: "; 8: cin >> RedSoxScore; 9: 10: cout << "\nEnter the score for the Yankees: "; 11: cin >> YankeesScore; 12: 13: cout << "\n"; 14: 15: if (RedSoxScore > YankeesScore) 16: cout << "Go Sox!\n"; 17: 18: if (RedSoxScore < YankeesScore) 19: { 20: cout << "Go Yankees!\n"; 21: cout << "Happy days in New York!\n"; 22: } 23: 24: if (RedSoxScore == YankeesScore) 25: { 26: cout << "A tie? Naah, can't be.\n"; 27: cout << "Give me the real score for the Yanks: "; 28: cin >> YankeesScore; 29: 30: if (RedSoxScore > YankeesScore) 31: cout << "Knew it! Go Sox!"; 32: 33: if (YankeesScore > RedSoxScore) 34: cout << "Knew it! Go Yanks!"; 35: 36: if (YankeesScore == RedSoxScore) 37: cout << "Wow, it really was a tie!"; 38: } 39: 40: cout << "\nThanks for telling me.\n"; 41: return 0; 42: } Output: Enter the score for the Red Sox: 10 Enter the score for the Yankees: 10 A tie? Naah, can't be Give me the real score for the Yanks: 8 Knew it! Go Sox! Thanks for telling me.

#include<iostream> #include<conio.h> using namespace std; void main() { float Call_Amount, Call_Duration,Additional_Minutes,Additional_Charge; Call_Amount = 3.99; cout<<"Please input the duration of call(in minutes):"; cin>>Call_Duration; if (Call_Duration > 3) { Additional_Minutes = Call_Duration - 3; Additional_Charge = Additional_Minutes * 0.45; Call_Amount = Additional_Charge + Call_Amount; cout<<Call_Amount<<endl; cout<<"Call lasted for "<<Call_Duration<<" minutes. Call amount is "<<Call_Amount<<"."; } else { cout<<"wrong data"; } getch(); }

/ custom countdown using while #include <iostream> using namespace std; int main () { int n; cout << "Enter the starting number > "; cin >> n; while (n>0) { cout << n << ", "; --n; } cout << "FIRE!\n"; return 0; }

You might also like