Practice Problem

Hey everyone,
I have just recently started programming, and I never gotten deep into C++. I bought a book with some extra practice problems in the back, yet they don't seem to have any answers. If someone could give me the code for these 3 problems, I would GREATLY appreciate it. Thanks!


Write a program that will generate a random number larger than 10,000 and then output the digits as words. For example, 345678’s output would be:
The Value is: 345678
Three Four Five Six Seven Eight


Write a program that creates a scrolling message display with characters entering from the right. For example, the message: Vote Yes!’s output would be:
Vote Yes!
ote Yes! V
te Yes! Vo (and so on)


A fast food restaurant charges $3.50 for a burger, $1.50 for fries, $1.75 for a drink or a combo meal for which includes all three items for $6.25.
Create a program that allows the cashier to enter their name and calculates the bill. They should be asked if they are purchasing a combo or individuals item. They should be asked how many combo meals and/or individual items should be purchased
Once everything is entered, the program should write out a “receipt” in which the user (cashier) should enter the money he was given. Once that is done, the program should calculate the change that needs to be given.
Do your own homework this forum is to help programmers not to do your homework
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

#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <string>
#include <cctype>//library to use 'toupper', 'tolower'....
#include <vector>
#include <fstream>
#include <stdlib.h>
#include <locale>
#include <iomanip>
#include <sstream>
using namespace std;
using std::ifstream;
using std::ofstream;
using std::endl;
using std::ios;

const int SIZE=56;



int main()
{
	int i=0;
	string line;
	srand((unsigned)time(0));
	int random=rand()%10000+30000;
	cout<<"Random Number is: "<<random<<endl;
	stringstream ss;
	ss<<random;
	ss>>line;
	
	for(i=0;i<line.length();i++){
		switch(line[i]){
		case '0':cout<<"Zero ";break;
		case '1':cout<<"One ";break;
		case '2':cout<<"Two ";break;
		case '3':cout<<"Three ";break;
		case '4':cout<<"Four ";break;
		case '5':cout<<"Five ";break;
		case '6':cout<<"Six ";break;
		case '7':cout<<"Seven ";break;
		case '8':cout<<"Eight ";break;
		case '9':cout<<"Nine ";break;
		default:cout<<"Good luck ";break;
		}
		
	}

	_getch();
	return 0;
}	

Jorz, I graduated college years ago! However, I have taken interest to programming, and to my misfortune, this book only has even number answers in the back.

And thanks toomanystars
Last edited on
Sure no problem. For the third problem, are those the exact directions? Are you supposed to use array? What are the major points in the chapter?

If I have time tomorrow, I will post the other two, but probably not since I have a class in the evening after work.

Mike
Hey Mike,
Yes this is in the array section of my book, most of the problems I have been doing rely on if thens, do whiles, for nexts, basic functions, counters, and other simple stuff

Thanks!
Here you go, this is the second one. I don't have time to do the third one tonight, sorry.

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


//#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <iomanip>
#include <sstream>
#include <cmath>
using namespace std;
 



int main()
{
 string line;
 cout<<"Enter a line of text\n\n";
 getline(cin,line); 
 cout<<"_____________________"<<endl;
 int i=0,j=0;
 int total=line.length();
 while(total>0){
         
  for(j=0;j<total;j++){
   cout<<line[j];      
  }   
  cout<<endl;    
  total--;
  
 }
 
                    
 _getch();
 return 0;
}



Cool! This is great! Once I have the last one I'll be all set, Thanks.
And the 3rd:

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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <iostream>
using namespace std;

int main(){
	int option = 0;
	int mealCount = 0;
	int sideCount = 0;
	int drinkCount = 0;
	int orderAmount = 0;

	bool loopOrder = true;
	bool makeCombo = false;
	bool pRec = false;

	float current = 0.0;
	float total = 0.0;
	float cashIn = 0.0;
	float cashOut = 0.0;

	while(loopOrder){
		cout << "_______________" << endl;
		cout << "| Menu Items: |" << endl;
		cout << "|             |" << endl;
		cout << "| 1. Burger   |" << endl;
		cout << "| 2. Fries    |" << endl;
		cout << "| 3. Drink    |" << endl;
		cout << "| 4. Cash out |" << endl;
		cout << "|             |" << endl;
		cout << "| 0. Exit     |" << endl;
		cout << "_______________" << endl;

		cin >> option;

		switch (option){
		case 1:
			cout << "Make this meal a combo? (1 - Yes, 0 - No) ";
			cin >> makeCombo;
			cout << "How many: ";
			cin >> orderAmount;
			if(makeCombo){
				mealCount = mealCount + orderAmount;
				sideCount = sideCount + orderAmount;
				drinkCount = drinkCount + orderAmount;
				current = current + (6.25 * orderAmount);
				cout << "Added " << orderAmount << " Combos" << endl;
				cout << "Current Total: " << current << endl;
				orderAmount = 0;
			}else{
				mealCount = mealCount + orderAmount;
				current = current + (3.50 * orderAmount);
				cout << "Added " << orderAmount << " Burger" << endl;
				cout << "Current Total: " << current << endl;
				orderAmount = 0;
			}
			break;
		case 2:
			cout << "How many: ";
			cin >> orderAmount;
			sideCount = sideCount + orderAmount;
			current = current + (1.50 * orderAmount);
			cout << "Added " << orderAmount << " Fries" << endl;
			cout << "Current Total: " << current << endl;
			orderAmount = 0;
			break;
		case 3:
			cout << "How many: ";
			cin >> orderAmount;
			drinkCount = drinkCount + orderAmount;
			current = current + (1.75 * orderAmount);
			cout << "Added " << orderAmount << " Drink(s)" << endl;
			cout << "Current Total: " << current << endl;
			orderAmount = 0;
			break;
		case 4:
			total = current;
			loopOrder = false;
			break;
		default:
			exit(0);
			break;
		}
	}

	cout << "Meals: " << mealCount << endl;
	cout << "Sides: " << sideCount << endl;
	cout << "Drinks: " << drinkCount << endl << endl;
	cout << "Total: $" << total << endl;
	cout << "Payment received: $";
	cin >> cashIn;
	cashOut = cashIn - total;
	cout << "\nChange: $" << cashOut << endl;

	cout << "Print Receipt? (1 - Yes, 0 - No) : ";
	cin >> pRec;
	
	if (pRec){
		cout << "________________________" << endl;
		cout << "|       Receipt" << endl;
		cout << "| Thank you, Enjoy" << endl;
		cout << "|" << endl;
		cout << "| Meals:  " << mealCount << endl;
		cout << "| Sides:  " << sideCount << endl;
		cout << "| Drinks: " << drinkCount << endl;
		cout << "|" << endl;
		cout << "| Total:  $" << total  << endl;
		cout << "| Paid:   $" << cashIn << endl;
		cout << "| Change: $"<< cashOut << endl;
		cout << "________________________" << endl;
	}else{
		exit;
	}

	system("PAUSE");

	return 0;
}
Last edited on
Topic archived. No new replies allowed.