Tilted Forum Project Discussion Community

Tilted Forum Project Discussion Community (https://thetfp.com/tfp/)
-   Tilted Technology (https://thetfp.com/tfp/tilted-technology/)
-   -   Help with code (https://thetfp.com/tfp/tilted-technology/44121-help-code.html)

PoteMatic 02-03-2004 05:56 AM

Help with code (C++)
 
Ive been behind and i just got an assignment but dont know how to do it so im gonna ask for some help.

The instructions are as follow:

1. Name the program ch4grade.cpp

2. Make sure the program name and the author's name is in comments at the top of the page

3. Put COMMENTS before EACH SECTION

4. Declare 5 char constants:
GRADE_A initialized to 'A'
thru
GRADE_F initialized to 'F'

--- compile your program here ---

5. Declare a char variable named myGrade

--- compile your program here ---

6. Assign the grade you'd like to recieve in this class to my_grade equal to in one of the constants GRADE_A thru GRADE_F.

--- compile your program here ---

7. Display your grade with a cout statement that says something like:
My name is xxxx.
The grade I'd like to recieve in C++ is...

-- compile and run your program ---


I have no clue on how to do any of this...

zenmaster10665 02-03-2004 06:09 AM

Not trying to be rude, however, how did you make it to Chapter 4 without knowing how to:


1. Name a program ch4grade.cpp

2. Make sure a program name and the author's name is in comments at the top of the page

3. Put COMMENTS before EACH SECTION

4. Declare char constants:

5. Declare char variables...

;)

PoteMatic 02-03-2004 06:11 AM

Well this is the first actuall program we have done lol the class/teacher is not very good and I have not learned anything.

Fallon 02-03-2004 07:49 AM

Do you have a book? Cause that's how I learned all my stuff.
Try writing the program first, because it's a pretty easy assignment. If you have troubles after writing it, post your code on here, and someone will be able to help.

The_Dude 02-03-2004 09:13 AM

yeah buddy, if we help u out with stuff like this, you will never get anywhere.

i say you turn to the section on variable declarations and take it on from there.

good luck :D

PoteMatic 02-03-2004 09:23 AM

Alright well thanks for not just giving me the answer and giving me some advice instead. Ill get the book and try it.

numist 02-03-2004 09:28 AM

declaring a variable is an easy process:

typeofvar varname = initializedvalue;

for constants, like your GRADE_A - GRADE_F, you want to use the const modifier so the program cannot change the values after they have been initialized.

Assigning values is a simple mathematical operation, so Ill leave that out.

As far as printing, there are a few functions you can use, I reccoment you lookup the man pages (or go online) for cout.

Oh yeah, and read through that book...

PoteMatic 02-04-2004 06:32 AM

So far ive got
 
So far for my code i have

Quote:

//Variables and Constants
//
//Author: J-Bo

#include <iostream.h>

main()
{
//Part4 - declare variables
int grade. b;//b will be used to hold age
float a;//a will be used to hold temperature

//Part 5 - declare constants
const float TEMPERATURE=72.5;
const int YOUR_AGE=16;

//Part6 - intalize variables
a=TEMPERATURE;
grade=11;
b=YOUR_AGE;


//Part 7 - Display the results

cout <<"I am in grade " << grade << " at Osceola High" << endl


return 0;
}
When compiled i got three errors I cant find um so let me know if you can

Artsemis 02-04-2004 06:41 AM

Your compiler should give you hints; always start with the top error in the list and recompile.

Here's what I see at a glance:
int grade. b;//b will be used to hold age

Should be:
int grade, b;//b will be used to hold age


and you need a semicolon at the end of your cout statement

PoteMatic 02-04-2004 06:43 AM

Thanks

PoteMatic 02-04-2004 06:48 AM

Fixed um all and its runs fine thanks for all the help... I jsut got another assignment so will probably have some more questions.

nukeu666 02-04-2004 10:21 AM

what youu really need is to learn cpp SYNTAX!!!
get any book and read the 1st few chapters...atleast the semicolon/;, stuff will be clear

nukeu666 02-04-2004 10:26 AM

Quote:

When compiled i got three errors I cant find um so let me know if you can
al compilers i've sen always tell you the line number where the errors are...
which compiler are you using?
i think you can download borlands compiler for free after registering on their site
devCPP is also a free compiler

PoteMatic 02-05-2004 05:55 AM

We are using borland im sick today kinda feelin run down not gonna do much ill get back to it tomorrow.


All times are GMT -8. The time now is 09:31 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project


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