Jump to content

Recommended Posts

Posted (edited)

Started a programming course today (applied some 6 months ago).

 

Got this thought, "Hey, could I share any of the knowledge at the pace that I am learning it myself?" (see Sources at the bottom of this post), so yeah, do what you will with it :)

 

It is very basic stuff and only 2 months of length (Programming One and Programming Two). Thought it'd be fun to discuss, and perhaps you can learn something from it as well.

 

Like, this,

Homework1:

"Historically speaking, computers haven't been around too long. The last 20 years, however, development has been rising at a rushing speed. Today in society there are computers and programs in many different forms. Even if we don't think about it we still use products that have been programmed for our daily uses, e.g., when we fuel the car, cash some money at the ATM or when we scan groceries in the local grocery.

 

Imagine that we turn back time about 30 years. Which computer related product would you miss the most that you use today? Which computer related product do you think has influenced the environment with most development the past 30 years, it can be in both positive or negative sense. Motivate your choices and provide source if you refer to fact."

 

Homework2:

"Write a program that involves a menu with alternatives. It could, per example, be a lunch menu for a restaurant. Example provided:

 

***Menu***

1. Monday

2. Tuesday

3. Wednesday

4. Thursday

5. Friday

0. Abort

Write choice: 1 <enter>

 

Monday serves cooked potato, beef and rich swamp* mushroom sauce.

 

Above the user has chosen alternative 1 and the food of the day is written on the screen. For the choices, 1-5, different food will be presented.

 

When the user writes 0, the program aborts. You must have one "while-loop" that steers the menu, as well as if-statements that controls the users choices. Remember to comment your code.

 

Sources: This is what I'm using, there is course literature as well but I don't have it just yet. Internet basically, holds all the knowledge any course literature has (and more).

* http://en.wikibooks....C _Programming which isn't 100% finished (some stuff in there dated 2006 so I don't think it ever will).

* Google is your friend :) "How to program C++?"

I am also using a .pdf that I found in Swedish. Google translate?:

* http://www.alesnaweb...mmering_ett.pdf

 

* " svamp = mushroom" in Swedish :p

 

On being teleported back 30 years, to early 80's... what would I miss? The world in my pocket. Communication. Mobility. Accessibility. The ability to communicate with- and travel the world with greater ease. Coming both more virtually and physically close as one world. I'd miss that progress of that (which is also what I think has grown most in the past 30 years). To be honest, if I were in the early 80's and 24 I'd probably just enjoy myself while it lasted before waking up from some strange dream.

 

The mobile internet.

 

What would you miss?

What do you think has evolved the most in the past 30 years?

Edited by Osvir
Posted

Just to play the devils advocate, I think I miss the 80'es when computers were a rarity and you didn't get pestered 24/7 by mobile devices, people actually talked to each other and Tron was was some LSD dream about what the future would look like.

 

Honestly, the only thing I think the world would miss would be some of the advances done in medico science thanks to the increase in computing powers and simulations.

  • Like 2

“He who joyfully marches to music in rank and file has already earned my contempt. He has been given a large brain by mistake, since for him the spinal cord would surely suffice.” - Albert Einstein
 

Posted

I think it just should be a console application... so the code:

 

#include stdio.h

 

MenuFunc()

{

int nInput;

int nState = 1;

printf("***Menu***\n1. Monday\n2. Tuesday\n3. Wednesday\n4. Thursday\n5. Friday\n0. Abort\n");

while (nState != 0)

{

printf("Make your Choice:");

scanf("%d",&nInput);

if (nInput>0&&nInput<6)

{

switch(nInput)

{

case 1:

printf("Monday serves Roast Beef + Chocolate Croissant");

break;

case 2:

printf("Tuesday serves Red Wine Chicken with Oiled Bok choy");

break;

case 3:

printf("Wednesday serves Smoking Duck with Parsley Mayonnaise");

break;

case 4:

printf("Thursday serves sizzling beef with beholders' eyes");

break;

case 5:

printf("Friday serves frozen lobster and dragon meat");

break;

case 0:

printf("Thanks for using");

nState = 0;

break;

}

}

else if

{

printf("Are ye blind? Ye meking trouble, aren't ye? Ken ye just pik 0-5? Blast ye!");

}

}

return 0;

}

 

 

As I can't remeber some rules clearly, it might be some small error in the code...

  • Like 1

I have struggle to understand a Universe that allows the destruction of an entire planet. Which will win this endless conflict - destruction or creation? The only thing I know for certain is never to place your faith entirely on one side. Play the middle if you want to survive.

 

Everyone else is a fanatic. I am Gauldoth Half-Dead. Your savior.

Posted

You could substitute the case statement with an array of text strings...

 

(assign values to text strings)

 

while stuff != done

{

...

printf(response[nChoice]);

...

}

 

You could read the text strings from a localised text file, depending on Windows language settings) and make your menu program truly international :)

  • Like 1

“He who joyfully marches to music in rank and file has already earned my contempt. He has been given a large brain by mistake, since for him the spinal cord would surely suffice.” - Albert Einstein
 

Posted

30 years ? I'd miss colour monitors and Sound Blasters :p

 

The array method is nice, if you're using numbers for the selections. For some reason I started thinking that we'd make a Day object that has a MenuList object that has a list of Food objects...then I forgot why I was doing it that way. OO-wankery I suppose.

Why has elegance found so little following? Elegance has the disadvantage that hard work is needed to achieve it and a good education to appreciate it. - Edsger Wybe Dijkstra

Posted

You could substitute the case statement with an array of text strings...

 

(assign values to text strings)

 

while stuff != done

{

...

printf(response[nChoice]);

...

}

 

You could read the text strings from a localised text file, depending on Windows language settings) and make your menu program truly international :)

 

Yeah,that's right. I just thought what Osvir provide the homework is just a simple program, and I just considered it must be kind of win32 console application, so I just write like that. And if there was a database or some how the localised text file like you said, the way you suggested is absolutely better.

I have struggle to understand a Universe that allows the destruction of an entire planet. Which will win this endless conflict - destruction or creation? The only thing I know for certain is never to place your faith entirely on one side. Play the middle if you want to survive.

 

Everyone else is a fanatic. I am Gauldoth Half-Dead. Your savior.

Posted (edited)

I'd miss a lot of people as well, but I am sure I would meet a lot of people.

 

Negative impact about the mobile internet is that those that are close get a little bit more distant. We communicate much further long distance today, some of my best friends live on the other side of the planet. 30 years ago it'd cost a lot for that long-distance phone call, or through that 56k internet connection (Anyone remember that "Ring ring!"?).

 

Cool with the code, I haven't done the assignment yet, and I don't want to cheat so I just took a quick glance at it. I want to understand why it works.

 

A console program is correct.

 

These are weekly, next week there'll be 2 new assignments etc. etc.

 

Just to play the devils advocate, I think I miss the 80'es when computers were a rarity and you didn't get pestered 24/7 by mobile devices, people actually talked to each other and Tron was was some LSD dream about what the future would look like.

 

Honestly, the only thing I think the world would miss would be some of the advances done in medico science thanks to the increase in computing powers and simulations.

 

Well, agreed. If I were in the 80's I'd probably feel a breather as well. One of the "revolution" with mobile internet is that you are now more and more able to work wherever you are on the planet for whatever company. 30 years ago a company I worked for sent out employees (trusted employees) to do jobs in the world and the company wouldn't be able to contact the employee in the same way, it could take a week before they knew what was going on.

 

Today I can call from my cell phone, wherever I am, to wherever I want (where there is service). From mobile phone to America.

 

With Facebook I randomly stumbled over a job that a friend presented on his wall. I took the risk, 15 minutes later I had a ticket to Austria. Worked there 3 days, 1 month later I had tickets to Fort Worth, Dallas. Regardless, that is also something about the mobility.

 

I can buy plane tickets that take me to another part of the world, from my mobile phone. There are probably programs and applications for it as well :) I believe in technology a lot, that it can help humanity. But it can also be used to control humanity, "herd" humanity I guess.

 

Negatively, there's so many gadgets everywhere, applications, pop ups, updates, socially pre-Wall-E. Facebook was probably really great in concept, Mark Zuckerberg might've had a beautiful vision about it "Now everyone can be friends!" and then it turned into a soap opera by the users themselves and Mark was probably just happy to become a millionaire/billionaire or whatever he is.

 

"Information" also more and more becomes a computer related product. I'd probably miss that as well (the ability to access so much information).

Edited by Osvir
Posted

"Information" also more and more becomes a computer related product. I'd probably miss that as well (the ability to access so much information).

Yeah,that's why they called IT as "Information Tech", I thought.

In the early year, we just got the info from paper, TV, radio etc. So that time is like the people are seeking information, and the limited ways of gathering info. But then we got internet and so far the mobile device, information now was coming to you, even you don't seek it positively.Still remeber when I was in high school, I bought a game magazine monthly just for a walkthrough or just 1 or 2 of the news, as we didn't get another ways to access it. But now days, I just go to a game website, I can got whatever I want. The same happens when you ask a location, now the younger are no longer like to ask a person that got at the street, but use google map on mobile.

Good or Not, hard to say. But I do know that it's price of the tech-development.

I have struggle to understand a Universe that allows the destruction of an entire planet. Which will win this endless conflict - destruction or creation? The only thing I know for certain is never to place your faith entirely on one side. Play the middle if you want to survive.

 

Everyone else is a fanatic. I am Gauldoth Half-Dead. Your savior.

Posted (edited)

The good is that the internet and the information is free.

The bad is that internet is turning into a corporate business more and more. There are already "borders" on the internet, and if the evolution of it goes the wrong way we might find ourselves stuck on "American Internet" versus "European Internet".

 

Already internet is starting to get "individualized". Facebook blocks out a ton of news feed, as an example, that in itself is like a "border". If I want specific information I have to search for it, whilst Facebook gives me the information it thinks I want depending on how I surf the internet.

 

EDIT: Oh right I can't get Visual Studio 2010 to work... anyone got any clues? This is what I get on this code:

 

#include <iostream>

 

int main() {

std::cout << "Hello World!" << std::endl;

std::cin.get();

return 0;

}

 

 

1>------ Build started: Project: Lesson1, Configuration: Debug Win32 ------

1>LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

 

http://xoax.net/cpp/...essons/Lesson1/

 

EDIT: This might be a solution to my problem:

http://stackoverflow.com/questions/10888391/link-fatal-error-lnk1123-failure-during-conversion-to-coff-file-invalid-or-c

 

 

This MSDN thread explains how to fix it.

To summarize:


  • Either disable incremental linking, by going to
    Project Properties
    -> Configuration Properties
    -> Linker (General)
    -> Enable Incremental Linking -> "No (/INCREMENTAL:NO)"
  • or install VS2010 SP1.

 

Here's Visual Studio SP1:

http://www.microsoft.com/en-us/download/details.aspx?id=23691

Edited by Osvir
Posted

well, I can't say much about the business and "border", it's bit complicated, just want to say you people are still lucky, if you are in China, you might totally know what the "border" means, Ha! Blast the Great Fire Wall.

I have struggle to understand a Universe that allows the destruction of an entire planet. Which will win this endless conflict - destruction or creation? The only thing I know for certain is never to place your faith entirely on one side. Play the middle if you want to survive.

 

Everyone else is a fanatic. I am Gauldoth Half-Dead. Your savior.

Posted (edited)

So been studying Sandro's code as well as trying to figure out how.. eventually I was sitting with something that I had mostly written myself (which was a great feeling) and now I've been trying to solve this problem for about an hour and... here it is :)

 

Progress is always fun!

#include <iostream>

 

int main()

{

int nInput;

int nState = 1;

std::cout << ("***MENU***\n1. Monday\n2. Tueday\n3. Wednesday\n4. Thursday\n5. Friday\n0. Abort\n") << std::endl;

do

{

std::cout << ("\nInput Choice: ");

std::cin >> nInput;

if (nInput>=0&&nInput<6) // if the user input is greater than or equal to 0 And if user input is less than 6)

{

switch(nInput) // a multiple functional switch with 6 buttons (1-5 and 0)

{

case 1:

std::cout << ("Monday Time") << std::endl;

break;

case 2:

std::cout << ("Tuesday Time") << std::endl;

break;

case 3:

std::cout << ("Wednesday Time") << std::endl;

break;

case 4:

std::cout << ("Thursday Time") << std::endl;

break;

case 5:

std::cout << ("Friday Time") << std::endl;

break;

case 0:

std::cout << ("Aborting...") << std::endl;

return 0;

}

}

else if(nInput>=6) // if the user input is greater than or equal to 6

{

std::cout << ("Invalid choice. Input a number between 0-5") << std::endl;

}

 

} while (nState != 0); // ask for "Input Choice?" from user while nState is "Not 0".

}

 

I'm curious if there is some way to do a "callback" on the "Menu". Some sort of "Back" command that takes me back to the start of the program and/or simply brings up the "Menu".

 

EDIT:

More C++ Resources for the interested:

http://www-numi.fnal...crib/index.html

 

Large database of knowledge:

http://www.cprogramming.com/begin.html

 

Haven't checked this one out but it looks good:

http://www.tutorials...splus/index.htm

Edited by Osvir
Posted

"Go To Statement Considered Harmful" - Edsger Dijkstra (1968)

 

No callback. It's blasphemy.

 

What you can do is "nest" more loops within each other. A main menu function loop that you return to after executing the menu selection function

 

I.e. put the entire switch/case thing in a separate function and call it from the main menu/title loop (so your start menu text gets inside the outer do while loop) :)

  • Like 1

“He who joyfully marches to music in rank and file has already earned my contempt. He has been given a large brain by mistake, since for him the spinal cord would surely suffice.” - Albert Einstein
 

Posted

You're welcome Osvir. It brings back a few memories from 30 years ago when I had to teach myself programming :)

“He who joyfully marches to music in rank and file has already earned my contempt. He has been given a large brain by mistake, since for him the spinal cord would surely suffice.” - Albert Einstein
 

Posted

If transported back 30 years ago, I'd miss some of the people I didn't meet until later on, but I'd enjoy the company of people I knew then who've sadly passed. I'd miss a little some of the movies that had not yet come, eg: 'Braveheart', and on some levels I'd miss some of the technology but not most of it. What I'd miss I'd gladly trade for what would be gained. But there were great movies back then (and more of them), great books (there's too many good ones to read them all in a lifetime), people looked better (far less couch potatoes (nowadays computer chair potatoes) and corn syrup and chemicals (cheap alternatives to the real thing) weren't yet widely used in food), many more things were still made in the USA, and overall the quality of goods almost everywhere was better (there's so much cheap plastic @#$* these days), and as Gorth mentioned people TALKED to each other.

 

Overall though, I'd take an 80s tech world over today's tech world in a heartbeat. It was a far more social world, in the meaningful ways. Even ten years ago before everyone and their grandmother got a cell phone it was a far more social world. People still commonly wrote letters, nowadays few do. Emails are not hand written letters.

 

If you wanted to talk to someone just randomly showing up at their house wouldn't be considered weird or creepy. And people randomly showed up at your house which could be a really nice surprise (nowadays it's custom to text before stopping by). If you were interested in a girl or guy randomly showing up at their house beat the hell out of all the text message games and sexting crap of today. You had to either drum up the courage to look them in the eye and talk or at least make the phone call.

 

People are losing touch with their humanity and the younger generations that don't know what life is like without the internet largely lack many important communication skills, not all of course, but most. People hide behind the internet, behind text messages. People used to hide behind a phone, still do, but that's still far better than hiding behind text.

 

Something that happened to me in 1998 when I was in college that made a big impression:

 

Around Memorial Day there was a huge storm that knocked down trees and the power and telephone lines (land lines, I was one of the very few that had a cell phone then) were out of almost a week or over a week depending on where in town you lived. School (Syracuse Univ) was closed for the first time in decades for more than one day due to, well anything.

 

What happened? Without electricity or telephones people walked outside and communicated with one another far more so than you saw at the time. Candles were broken out, hide and seek was played on large scale (after the early 90s it's been near impossible to do this due to so many motion detector lights and oh do I feel sorry for the younger folks who've never experienced the epic 2-3 city block hide and go seek matches in the dark with 10-20 peoples, nothing better except maybe sex), BBQs emass with neighbors, nearly every porch on the street had people on it nearly all day, people had to come up with things to do that didn't involve video games, or vegging in front of a TV.... in short it was a throwback to a decade or two earlier when people did communicate with one another more and got to know their neighbors. That was 1998, the internet was still somewhat in it's infancy, while exploding not everyone and their grandmother had gotten a computer yet (even in college). Even at that time the antisocial behaviors of society were beginning to really show their growth, and 1998 is a far cry in terms of the widespread use of computers and cell phones that we see now.

 

Some, especially the younger, will decry what I've written as just nostalgia, that I'm seeing the world through rose colored glasses. No, I'm not. Things weren't perfect back then and a few things have improved, but as a society as a whole for all we've gained we've lost a lot. I could point to modern day examples of communities where cell phones still don't work (they're rare but they exist.... I don't live too far from the Adirondaks), and internet is dial up or satellite and most don't have it. In those places people still TALK and do things with each other face to face more on average than elsewhere.

 

The world has come together over the internet but as much as that is true, it's also true that it's become more fractured in many ways.

 

Anyways.. I'm off to get a beer and Pac Man is still one of the greatest video games ever. Asteroids not far behind.

  • Like 1
Posted (edited)

All those stds... Type using namespace std; after the include, then you can just use cout without specifying which class it belongs to, so without std::

 

Instead of using cin to avoid the console to close, use system("pause");

 

Write cases in one line, less lines. Only use do-while when absolutely required, most of the time use a simple while.

 

I know a very good C++ tutorial in French, you'll be able to learn the basics of c++ in 2 hours, then classes in about a day, then polymorphisms etc, then there's even a tutorial for Qt and some 2d graphics library. Know nothing of the sort in English unfortunately. Interested?

 

upd

Maybe paste your code on pastebin.com in the future? at least for indentation purposes.

Edited by Bester
  • Like 1
IE Mod for Pillars of Eternity: link
Posted

There are also code tags on the boards :)

 

void main(int argc char **argv)
{
 printf('Hello world\n');

 while !finished
 {
   // Do more stuff
 }
}

  • Like 1

“He who joyfully marches to music in rank and file has already earned my contempt. He has been given a large brain by mistake, since for him the spinal cord would surely suffice.” - Albert Einstein
 

Posted (edited)

All those stds... Type using namespace std; after the include, then you can just use cout without specifying which class it belongs to, so without std::

 

Instead of using cin to avoid the console to close, use system("pause");

 

Write cases in one line, less lines. Only use do-while when absolutely required, most of the time use a simple while.

 

I know a very good C++ tutorial in French, you'll be able to learn the basics of c++ in 2 hours, then classes in about a day, then polymorphisms etc, then there's even a tutorial for Qt and some 2d graphics library. Know nothing of the sort in English unfortunately. Interested?

 

upd

Maybe paste your code on pastebin.com in the future? at least for indentation purposes.

 

Yeah my teacher gave me the same feedback on the underline :)

 

Thanks on the rest, going to try to suck it in but I think it is a bit too soon for me (in essence: I understand what you are talking about but I wouldn't be able to understand where to put it in the code). My current level is-, and what I could write from memory, "Hello World" code (and that Menu thing ofc).

 

Programming language is like the Spanish language for me, I understand written Spanish fairly well and I understand spoken Spanish somewhat, but I only know how to speak a few sentences myself.

 

pastebin.com bookmarked ;)

 

There are also code tags on the boards :)

 

void main(int argc char **argv)
{
printf('Hello world\n');

while !finished
{
// Do more stuff
}
}

 

Can you compile & run code too? I found a tic-tac-toe console code :p

Edited by Osvir
Posted

Ifs and whiles are so 1970 :p

 

 

open System

let menus = 
   [| "Lutefisk";
      "Braunschweiger";
      "Liver Sausage Bologna Loaf";
      "Crockpot Chocolate Mess";
      "Troll Souflé" |]

let days = [| "Monday"; "Tuesday"; "Wednesday"; "Thursday"; "Friday" |]

let printChoices() = 
   printfn "*** Menu ***"
   days |> Array.iteri (fun index day -> printfn "%d. %s" (index + 1) day)
   printfn "0. Abort"

let rec getUserInput() =
   printfn "Write choice: "
   match Int32.TryParse(Console.ReadLine()) with
   | (false, _) -> 
       printfn "Invalid entry. Please retry."
       getUserInput()
   | (true, i) -> 
       match i with
       | i when 0 <= i && i <= menus.Length -> i
       | _ ->
           printfn "Invalid entry. Please retry."
           getUserInput()

let rec mainLoop() =
   match getUserInput() with
   | 0 -> printfn "Goodbye!"
   | i -> printfn "%s serves %s." menus.[i - 1] days.[i - 1]
          mainLoop()

do
   printChoices()
   mainLoop()

Posted

^My teacher told me to avoid printf and scanf (from the other post) so I'd avoid that.

 

Don't understand anything of that Zeckul but it looks interesting :D

 

This is how the menu ended up by the way:

#include <iostream>
using namespace std;
int main()
{
int choice; // integer variable, the player choice
bool gameOn = true; // the game is on
while (gameOn !=false) // while the game is not off do,
{
cout << "*************************\n\n";
cout << " 1 - Start Game.\n";
cout << " 2 - Hall of Fame.\n";
cout << " 3 - Help.\n";
cout << " 4 - Options.\n";
cout << " 5 - Exit.\n\n";
cout << "*************************\n\n";
// a list of choices
cout << "Enter your choice and press return: ";
cin >> choice;
// the user enters his/her choice
cout << "\n";
{
switch (choice) //buttons for the different choices
{
case 1: // If user enters 1, do
cout << "[ Under construction ]\n\n"; // here there could a variable and another while loop to iniate the game
break; //stops the loop and goes back to the start
case 2:
cout << "\n[1 - Ragnar - 974 points]\n"; // "1 - Ragnar -" << variable << "points"\n;
cout << "[2 - Olof - 874 points]\n";
cout << "[3 - Kalle - 200 points]\n\n";
//high score list for the user to see their points
break;
case 3:
cout << "\n[ Type 1-5 for choice ]\n\n";
//Help to understand how the program works
break;
case 4:
cout << "\n[ Graphics ]\n";
cout << "[ Sound ]\n";
cout << "[ Controls ]\n\n";
// la list for more choices
// a while loop could be put in here for a second list within the list
break;
case 5:
cout << "\n[ End of Program ]\n\n";
// self-explanatory
break;
default: // if 1-5 have not been pressed?
cout << "\n[ Invalid. ]\n";
cout << "[ Type in 1-5 ]\n\n";
break;
}
// While the user enters 1-5 different things happens
// If 1 the user should start the game
// If 2 the user should see their score
// if 3 the user should get help to understand the program
// if 4 the user should see another menu
// if 5 the user ends the program
// if 0&&6=<, 0 and equal to 6 and higher, the user should get notified that they have pressed wrong
}
if (choice == 5) // if the user enter 5
{
gameOn = false; // end the while loop which in turns ends the program
}
}
}

 

Now for week 2 :D

Assignment 2a

In subsection 1 was a task where you created a menu. Now I want to create a structure diagram or write pseudo code that describes the program.

Use the symbols in word, draw in paint or draw by hand scan and send the file in pdf format. Do you have another idea about how the task should be reported, check with the teacher if it is ok.

 

An assignment with several different approaches:

* Code in C++

* Write Psuedo Code (text)

* Use symbols in word (text)

* Draw in paint or by hand (artistic)

 

I am going for the first one and the second one.

 

Assignment 2b

Create a travel planer. The program will ask for the length in km. If the trip is 2 km or less to travel planner suggest a walk. If the trip is longer than 2 km and less than 8 km to travel planner propose cycle. Is the journey longer 8km or longer travel planner propose bus or car. After the proposed travel way, the program will ask if the user wants to continue y / n

 

There's an extra .pdf that we got (in Swedish ofc) about vectors and strings, so I'm guessing both of these functions are related.

 

Here's some resources if you wish to try it yourself (wanting to learn, required):

http://xoax.net/cpp/crs/console/index.php great videos and help

http://www.cprogramming.com/begin.html lots of documentation

http://en.wikibooks.org/wiki/C++_Programming a free wikipedia book (which isn't and will probably never be finished but it still has lots of documentation)

http://www.tutorialspoint.com/cplusplus/index.htm haven't checked this site much more than "bookmarked"

http://cplusplus.com/ this is what my school has recommended, but I've only bookmarked it thus far

Posted

:grin:

 

Not even pseudo code, but just one general idea for the travel planner...

 

Two arrays one of integers Distance[3] and one of zero terminated strings TransportMode[3].

 

Assign values

Distance[0] = 0

Distance[1] = 2

Distance[2] = 8

TransportMode[0] = "Legs"

TransportMode[1] = "Cycle"

TransportMode[2] = "Car"

 

Outer Menu Loop, show menu and ask for Actual Distance

 

Inner Loop - count i backwards from 2 to 0, if Actual Distance >= Distance then print TransportMode to console and exit inner loop

 

Not exactly the first kind of programs I did (didn't get a c compiler until years later), but it sure is fun with those little "challenges", teaches the mind to think in algorithms :)

“He who joyfully marches to music in rank and file has already earned my contempt. He has been given a large brain by mistake, since for him the spinal cord would surely suffice.” - Albert Einstein
 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...