Перейти к содержимому
View in the app

A better way to browse. Learn more.

Zloplay community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Is this how your write the pseudocode?

Опубликовано:

So I just got an assigment, it's kinda basic stuff but a guy like me who barely have any knowledge in coding is clueless. So I need help.

 

The assignment was to write the the procedure, input, process, output and some other stuff.

I was tasked to write down the pseudo codes and algorithm for temperature conversion. Fahrenheit to Celsius.

 

So mind if I ask you guys if I did this pseudo code right?

There two formulas I need to use for the conversion.

 

1st pseudo code : 5/9 * (F - 32)

 
Get type of conversion from user
Get Temperature to convert from user
If type of conversion is Fahrenheit-to-Celsius then
	ConvertedTemperature = 5/9 * (F – 32)
Else (type of conversion is Celsius-to-Fahrenheit)
	ConvertedTemperature = (9/5 * F) + 32
Display ConvertedTemperature

 

2nd Pseudo code : ½ * F – 15

 

Get type of conversion from user
Get temperature from user	
If type of conversion is Fahrenheit-to-Celsius then
	ConvertedTemperature = ½ * F – 15 
Else (type of conversion is Celsius-to-Fahrenheit)
	ConvertedTemperature = F + 15 * 2
Display ConvertedTemperature

Featured Replies

Опубликовано:

Looks good.

 

(amateurish code)

 

#include "stdafx.h"
#include 

using namespace std;

bool conversiontype;
float temperature;
float result;

int main ()
{
cout << "Enter 0 for Fahrenheit to Celsius, enter 1 for Celsius to Fahrenheit.\n";
cin >> conversiontype;
cout << "Enter your desired starting temperature.\n";
cin >> temperature;

if (conversiontype == true)
	result = temperature * 9/5 + 32;
else 
	result = temperature - 32;
	result = result * 5/9;

cout << result << "\n";
system ("PAUSE");
return 0;
}

 

(wrote this following your pseudocode, and it works fine, so I guess your pseudocode therefore must work)

Опубликовано:
So I just got an assigment, it's kinda basic stuff but a guy like me who barely have any knowledge in coding is clueless. So I need help.

 

The assignment was to write the the procedure, input, process, output and some other stuff.

I was tasked to write down the pseudo codes and algorithm for temperature conversion. Fahrenheit to Celsius.

 

So mind if I ask you guys if I did this pseudo code right?

There two formulas I need to use for the conversion.

 

1st pseudo code : 5/9 * (F - 32)

 
Get type of conversion from user
Get Temperature to convert from user
If type of conversion is Fahrenheit-to-Celsius then
	ConvertedTemperature = 5/9 * (F – 32)
Else (type of conversion is Celsius-to-Fahrenheit)
	ConvertedTemperature = (9/5 * F) + 32
Display ConvertedTemperature

 

2nd Pseudo code : ½ * F – 15

 

Get type of conversion from user
Get temperature from user	
If type of conversion is Fahrenheit-to-Celsius then
	ConvertedTemperature = ½ * F – 15 
Else (type of conversion is Celsius-to-Fahrenheit)
	ConvertedTemperature = F + 15 * 2
Display ConvertedTemperature

This is how I write my pseudo code(based on your code):

// Include needed headers

int main(int argc, char** argv)
{
   // Get type of conversion from user
   // Get temperature from user

   // If type of conversion is Fahrenheit-to-Celsius
   {
       // Convert the temperature using 5/9 * (F – 32)
   }
   // else if type of conversion is Celsius-to-Fahrenheit
   {
       // Convert the temperature using (9/5 * F) + 32
   }

   // Display the converted temperature
}

 

This way I think its clearer. Also you already define the functions you'll use so you can think about this when writing the pseudo code. Anyway your pseudo code is okay for small applications which do not have a lot of functions. Don't worry much about that, you'll skills writing pseudo code will improve if you use it enough.

 

This would be the result of the pseudo code:

// Standard header for every ANSI C program
#include 

// Required for windows
#include 

int main(int argc, char** argv)
{
   float temperature = 0.0; // Important to set it to 0.0 to prevent some compiler issues
   int temperatureType = 0; // 0 = C, 1 = F
   float result = 0.0;

   printf("Please select the input temperature type:\n");
   printf("1 -> Celsius to Fahrenheit\n");
   printf("2 -> Fahrenheit to Celsius\n");
   printf("Selection: ");

   temperatureType = (getchar() == '2') ? 1 : 0; // If getchar does not work, try with getch() 

   printf("Enter the %s value: ", (temperatureType == 1) ? "Fahrenheit" : "Celsius");
   scanf("%f", &temperature);

   if(temperatureType == 1)
   {
       result = (temperature - 32) * 5/9;
   }
   else
   {
       result = temperature * 9/5 + 32;
   }

   // There the condition is inverted so it can display the correct output temperature type
   printf("The %s converted temperature is: %f", (temperatureType == 1) ? "Celsius" : "Fahrenheit", result);
}

Опубликовано:
  • Автор

Apparently I messed up and I can't include a reversed conversion. Plus, my lecturer says I can't use if....else functions due to the fact that we still haven't learn it. (I swear I already learnt this thing back in middle school) Now, I can only use Accept, Display and Print. Is the code suppose to be that simple?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Гость
Ответить в тему...

Сейчас на странице 0

  • Нет пользователей, просматривающих эту страницу

Важная информация

Используя этот сайт, вы соглашаетесь Условия использования.

Account

Navigation

Поиск

Поиск

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.