Translate code into pseudo code

Write your question here.
Hello, I am done writing this code for my class and the next step is to turn it into pseudocode could someone give me an example of what it's supposed to look like

thanks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
 	#include <iostream>
	#include <iomanip>
	void Header()
	{
		std::cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n";
		std::cout << "@@@@@@@@@  APEX AUTO RENTALS   @@@@@@@@@      \n";
		std::cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n";
		std::cout << "\n";
	}

	 

	int main() {
		int miles, Days, amount, costc{ 17 }, costl{ 20 }, weeks, weeklycostc{ 145 }, weeklycostl{ 199 }, mpgc{ 30 }, mpgl{ 16 }, savedc, savedl;
		char cartype;

	 
	//Header function being called 
		Header();
		std::cout << "Please enter the following information: \n";
		std::cout << "\n";
		// Prompt user to enter type of car
		do {
			std::cout << "What class of car would you like? (C for compact L for Luxury):\n";
			std::cin >>cartype;
		
			switch (cartype) {
			case 'c':
		
				amount = 17;
				break;

			case 'l':
		
				amount = 20;
				break;
		
			default:
				std::cout << "invalid entry please try again" << cartype << "\n";
				break;
			
			}
		}
	// while function repeats if input is not c,C,l,L
		while ((cartype != 'c') && (cartype != 'l'));

	  // prompt user to input miles estimate
		std::cout << "How many miles will you drive? \n";
		std::cin >> miles;
		// prompt user to input Days 
		std::cout << "How many days will you be gone? \n";
		std::cin >> Days;
		// function to calculate weeks 
		weeks = Days / 7;
		//functions to calculate weekly costs
		savedc = ((costc * Days) + (0.28 * miles)) - ((weeklycostc * ceil(Days/7)) + ((miles * 0.28) / 30));
		savedl = ((costl * Days) + (0.33 * miles)) - ((weeklycostl * ceil(Days/7)) + (miles * 0.33 / 16));
	
		// display projected Daily cost
		
			if (cartype == 'c') {
				std::cout << "Projected cost of Daily Plan:     " << (costc * Days) + (0.28 * miles) << "\n";
			}
			else if (cartype == 'l') {
				std::cout << "Projected cost of Daily Plan:     " << (costl * Days) + (0.33 * miles) << "\n";
			
			}
		// if Days greater than or = 7 than display weekly calculation 
			 if (Days >= 7) {
			
			if (cartype == 'c') {
			
				std::cout << "Projected cost of weekly plan:   " << (weeklycostc * ceil(Days / 7)) + ((miles * 0.28)/30) << "\n";
				std::cout << "Customer will save "  << savedc << " by choosing the Weekly Plan \n";
			}
			else if (cartype == 'l') {
				std::cout << "Projected cost of weekly plan:   " << (weeklycostl * ceil(Days / 7)) + ( miles * 0.33/16) << "\n";
				std::cout << "\n";
				std::cout << "Customer will save " << savedl << " by choosing the Weekly Plan \n";
			}
			std::cout<<"Number of weeks:" << ceil(Days / 7.0);
		}
	
		}
	



Just explain what the program does, step by step, in plain text (some programming/math inspired syntax is usually OK). You probably still want to use indentation to make it easy to see what's inside loops and branches but leave out C++-specific details. Exactly how much details you can leave out depends on the purpose you intend to use the pseudocode for.
Last edited on
The code's comments are a "good start" at crafting some pseudo code equivalent. They say in simplified plain English text what the code is doing.

https://www.techgeekbuzz.com/how-to-write-pseudocode/

How elaborate your pseudo code ends up being is "what do you need the pseudo code for?"

Last edited on
> Hello, I am done writing this code for my class and the next step is to turn it into pseudocode
You did it the wrong way round then.

You don't build a house and then put the scaffolding up afterwards.

For example, the pseudo code you write before the code could become the comments in the code.
Hello, I am done writing this code for my class and the next step is to turn it into pseudocode


You usually design the program first - including pseudo code - and then code from the design.

Are you sure the class requirement is to produce pseudo-code from the actual code, and not to first produce pseudo-code and then actual code?
Slightly simplified code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <iomanip>
#include <cctype>
#include <cmath>

void Header() {
	std::cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n";
	std::cout << "@@@@@@@@@  APEX AUTO RENTALS   @@@@@@@@@      \n";
	std::cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n";
	std::cout << "\n";
}

int main() {
	constexpr int costc {17}, costl {20}, weeklycostc {145}, weeklycostl {199};
	unsigned char cartype {};
	int amount {}, miles {}, Days {};

	Header();

	std::cout << "Please enter the following information: \n";
	std::cout << "\n";

	do {
		std::cout << "What class of car would you like? (C for compact L for Luxury): ";
		std::cin >> cartype;

		switch (cartype = static_cast<unsigned char>(std::tolower(cartype))) {
			case 'c':
				amount = 17;
				break;

			case 'l':
				amount = 20;
				break;

			default:
				std::cout << "invalid entry please try again" << cartype << "\n";
				break;
		}
	} while ((cartype != 'c') && (cartype != 'l'));

	std::cout << "How many miles will you drive? \n";
	std::cin >> miles;

	std::cout << "How many days will you be gone? \n";
	std::cin >> Days;

	if (cartype == 'c') {
		const auto savedc {((costc * Days) + (0.28 * miles)) - ((weeklycostc * std::ceil(Days / 7)) + ((miles * 0.28) / 30))};

		std::cout << "Projected cost of Daily Plan:     " << (costc * Days) + (0.28 * miles) << "\n";

		if (Days >= 7) {
			std::cout << "Projected cost of weekly plan:   " << (weeklycostc * ceil(Days / 7)) + ((miles * 0.28) / 30) << "\n";
			std::cout << "Customer will save " << savedc << " by choosing the Weekly Plan \n";
		}
	} else {
		const auto savedl {((costl * Days) + (0.33 * miles)) - ((weeklycostl * std::ceil(Days / 7)) + (miles * 0.33 / 16))};

		std::cout << "Projected cost of Daily Plan:     " << (costl * Days) + (0.33 * miles) << "\n";

		if (Days >= 7) {
			std::cout << "Projected cost of weekly plan:   " << (weeklycostl * ceil(Days / 7)) + (miles * 0.33 / 16) << "\n";
			std::cout << "Customer will save " << savedl << " by choosing the Weekly Plan \n";
		}
	}

	std::cout << "Number of weeks:" << ceil(Days / 7.0) << '\n';
}

Topic archived. No new replies allowed.