Help With a Project for School [Old School C++] [BRANCHING]

This is my first post on here, so let me start off by saying, I have only been doing this kind of stuff for a month, I am very new to coding and programming and would appreciate as much help as I can get. I

I have a project for school. It's called 'Messages', and the teacher says it's not supposed to be that hard, some people in class have gotten it but I would like some extra help with everything.

Here is what I have to do for the project;

"Write a program that prints one of three APPROPRIATE messages depending on whether the user types 1, 2 or 3."

I have a majority of the project done (or a least I think I do) but there are a few things I still need help with.

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
//Taylor Lynch
//Messages
//Print 3 Messages
//Period 5

#include <iostream.h>
#include <conio.h>
#include <dos.h>
#include <stdio.h>

main()
{

	int x;
	textcolor(WHITE);
	cprintf("Enter either 1, 2 or 3: ");
	cin>>x;
	if(x>3)
	{
	cout<<”Number is not valid, Please try again”;
	getch();
	clrscr();
	cprintf(“New Number: “);
	cin>>x;
	}
	if(x<1)
	{
        cout<<”Number is not valid, Please try again”;
        getch();
 	clrscr();
        cprintf(“New Number: “);
	cin>>x;
	}
	if(x==1)
	{
	cout<<”What is a teacher without students?”;
	delay(100);
	cout<<” Happy.”
	}
	if(x==2)
	{
	cout<<”Student: Would you punish me for something I didn’t do?\n”;
	delay(200);
	cout<<”Teacher: Of course not.\n”;
	delay(200);
	cout<<”Student: Good, because I didn’t do my C++ assignment.\n”;
	}
	if(x==3)
	cout<<”Teacher: Where is your textbook?\n”;
	delay(200);
	cout<<”Student: It’s at my house.\n”;
	delay(200);
	cout<<”Teacher: Well, what is it doing there?\n”;
	delay(200);
	cout<<”Student: Having a better day than me.\n”;
	getch();
return 0;
}



(If I didn't enter the code correctly for the Forum, please also tell me how to do that, this is my first post

--------------------------------------------------

Basically I just want to know what is wrong with the code and how I could fix it, because I have no clue.

Thanks in advance!
Last edited on
Also, I have been told that the C++ that I am learning is a very old way of doing so, if this is correct, could someone tell me? Again, I have no idea.
From those headers and the function calls, that looks like Turbo C, which is antiquated and is not a C++ standards compliant compiler. If you're going to learn C++, you should be learning with a standards compliant compiler.

Line 11: main() must be type int.

Lines 16-33: You need a loop here. What happens if the second number the user enters is not valid?

Line 38: Missing ;

Lines 49-56: You're missing {} around these statements.

Lines 34-56: A switch is appropriate here.

Numerous places: You're using the wrong quotes. Should be ", not ” or “.



I am using Turbo C, the program is called TCLite.

Honestly, some of the things you said do make sense to me, at some don't at the same time. Would you mind editing my code and showing me what was done differently, so that I know for future reference.
If anybody could possibly fix my code, and show me exactly what I did wrong, and what I should be doing differently, that would be a HUGE help.

Thank you in advance to whoever is able to help me with this!
closed account (48T7M4Gy)
@TPL

This is not a homework site.

If you wrote the program you posted at the start I doubt whether you will have any trouble understanding and applying the changes that AbstractionAnon has kindly given you, especially the ones that make immediate sense to you.
some of the things you said do make sense to me, at some don't at the same time. Would you mind editing my code and showing me what was done differently,

I'm not going to rewrite your code for you. However, if there are specific things you don't understand in my previous response, please list the specifics you're not clear about and I will try to clarify.

Besides, if I were to rewrite it, it would be with a standards compliant compiler and would probably not compile with Turbo C.

Last edited on
@kemort I know its not a homework site. If I was looking for someone to do my homework, I would not be here, the assignment was due today, I got a ZERO on it. It doesn't bother me, but I asked for help. If you do not have any help or advice (again, which is what I asked for) then please do not comment.

@AbstractionAnon

I just have trouble understanding the loops, and how to make them work.

I also have no idea what a 'switch' is. I haven't used this before.
I just have trouble understanding the loops, and how to make them work.

I posted an explanation of using a loop to validate input here:
http://www.cplusplus.com/forum/beginner/175620/#msg868449

I also have no idea what a 'switch' is. I haven't used this before.

See the reference page here:
http://www.cplusplus.com/doc/tutorial/control/



Topic archived. No new replies allowed.