Blog Post 4 | 6/5/2019
Today, we learned more about C++, beginning to look into flow control and loops. We learned about if-else statements, switch statements, and while, do while and for loops. The importance of these in C++ cannot be overstated. In addition, my group and I worked more on our problem paragraph, which I feel is going well. I’m working on a program that reads in data from an Excel sheet and prints it out to the console so the user can interact with it. I’ve never read in an Excel file, but I’ve used a text file before, so I copied the data from the spreadsheet and put it in a text file, just to try and get it to work in a familiar setting. Once I get it working there, I’ll find out how to read in the Excel file.
#include <iostream>
#include <Windows.h>
//You need to modify this program to do the following steps
//1. Depending on their choice ask for corresponding values and print them out(almost done for you)
//1 b.See if you can change the if statements to a switch case
//2. Put entire structure in a loop that runs until I press q
//3. Make sure it checks for bad values(-ve numbers, words ? )
//4. Add perimeter calculations as separate choices
//*
using namespace std;
int main()
{
int length;
int breadth;
int lengthsquare;
float radius;
cout << "1. Rectangle area" << endl;
cout << "2. Square area" << endl;
cout << "3. Circle area" << endl;
cout << "What is your choice?" << endl;
char choice;
cin >> choice;
while (choice != 'q'){
switch (choice)
{
case '1':
cout << "What length?: ";
cin >> length;
cout << "What breadth?: ";
cin >> breadth;
cout << length * breadth << endl;
break;
case '2':
cout << "What length?: ";
cin >> lengthsquare;
cout << endl << lengthsquare * lengthsquare << endl;
break;
case '3':
cout << "What is the radius?:";
cin >> radius;
cout << endl << 3.14 * (radius*radius) << endl;
break;
default:
cout << "I don't understand.\n";
}
cout << "1. Rectangle area" << endl;
cout << "2. Square area" << endl;
cout << "3. Circle area" << endl;
cout << "What is your choice?" << endl;
cin >> choice;
}
system("PAUSE");
return 0;
}
#include <iostream>
#include <math.h>
using namespace std;
int fib(int n);
int main()
{
cout << "Tell me how far you want to fib?" << endl;
int choice;
cin >> choice;
cout << fib(choice + 1) << endl;
//TODO:Print out nth fibonacci number
system("PAUSE");
return 0;
}
int fib(int n)
{
if ((n == 1) || (n == 2))
return n - 1;
else
return fib(n - 1) + fib(n - 2);
}
Comments
Blog Post 4 | 6/5/2019 — No Comments
HTML tags allowed in your comment: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>