corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » anyone good with programming? (geeks only) » Post Reply

Post Reply
Who Can Post? All users can post new topics and all users can reply.
Icon:
Formatting Mode:
Normal
Advanced
Help

Insert Bold text Insert Italicized text Insert Underlined text Insert Centered text Insert a Hyperlink Insert Email Hyperlink Insert an Image Insert Code Formatted text Insert Quoted text
Message:
HTML is Off
Smilies are On
BB Code is On
[img] Code is On
Post Options: Disable smileys?
Turn BBCode off?
Receive email notification of new replies?

Paul_J

posted on 27th Oct 06 at 18:37

Also if your worried about losing the last screen that showed you the last grade result when you type a new grade in, remove the system("cls");

I'd personally have the test for the keypress at the end of the loop, not the start.

Do

While (keypress!="q")

this is because when you quit from the menu (press q) keypress will = q, and if later you need the menu to be recalled again, when it gets to the first part of the loop

While (keypress!="q") It now won't do this code, because keypress is still = q.

Where as using a

Do
<code here>
While bla bla bla - Would at least execute the menu system once before offering the person the choice to change the value of keypress again.


Paul_J

posted on 27th Oct 06 at 18:31

quote:
Originally posted by Ren
(C++)

I'm writing a program that converts numbers input to the program into grades in a simple fashion. I have everything sorted, all the coding is fine, all the formula's are right except one... Im trying to make it so after a grade has been given, the program contunues after for the next number to convert to a grade - but right now it'll delete what was already there and start afresh.

Here's the code anyway:
#include <iostream>
#include <conio.h>

int main()
{
int igrade =0;
char keypress;

while (keypress!='q')
{
std::cout << "# STUDENT GRADE PROGRAM #\n";
std::cout << "---------------------------\n";
std::cout << "Please enter Student Grade \n";
std::cin >> igrade;

//Formula for converting numbers to grades
if (igrade < 40)
std::cout << "\nStudent Has FAILED\n\n";
else
if (igrade < 60)
std::cout << "\nStudent Has a GRADE C\n\n";
else
if (igrade < 80)
std::cout << "\nStudent has a GRADE B\n\n";
else
if (igrade >= 80)
std::cout << "\nStudent has a GRADE A\n\n";
std::cout << "---------------------------\n";


std::cout << "\n\nTo quit, press Q or enter another grade to continue\n";
keypress=getch();
system("cls");
}
return 0;
}

Anyhelp anyone? :thumbs:

[Edited on 27-10-2006 by Ren]


Poor Code :o

I'd also make sure I had an include for stdio.h (standard input / output).

As pointed out by reedy, in the example above you have an integer, so you can only store 1 value in that integer at a time, so everytime you enter a grade the integer will get re-set to the new value (old value lost), so use an array, or some form of 'temp' value for storing the old grades.


Ren

posted on 27th Oct 06 at 17:01

quote:
Originally posted by Steve
i was saying the question you asked seemed to be more of a maths question than a programming one


Ah right. I was just frustrated with my coding, and i just took what you said the wrong way.

Thanks to all that helped, i havent got it sorted yet, but im nearly there :thumbs:


Ian

posted on 27th Oct 06 at 16:58

Tick 'Turn BB code off' or whatever its called.

This type of question is better solved as theory, showing syntax is OK but you don't learn anything being given the entire code.


Reedy

posted on 27th Oct 06 at 15:32

i did put that code in but it wont come up as the forum code for italic is the same lol.


Ian

posted on 27th Oct 06 at 15:26

I think Steve was meaning that you need to approach this problem as a design one rather than just altering code.

If you mean that you want to store all the results then you need an array, and you need to write the grade to the array at the end of the if conditionals then loop through that displaying all the grades when 'q' is pressed.


Reedy

posted on 27th Oct 06 at 12:22

try it now ive edited it and checked in visual stuido.


Reedy

posted on 27th Oct 06 at 12:06

Also that is a quick bodge as such.

Added you on msn, so if you come online i can do it privately :o

[Edited on 27-10-2006 by Reedy]


Reedy

posted on 27th Oct 06 at 12:04

#include <iostream>
using namespace std; //Means you dont have to put std everywhere
#include <conio.h>

int main()
{
int igrade[512];
int j = 0;
char keypress = ' ';


while ( keypress!='q' )
{
cout << "# STUDENT GRADE PROGRAM #\n";
cout << "---------------------------\n";
cout << "Please enter Student Grade \n";
cin >> igrade[j];

//Formula for converting numbers to grades
if ( igrade[j] < 40)
cout << "\nStudent Has FAILED\n\n";
else
if (igrade[j] < 60)
cout << "\nStudent Has a GRADE C\n\n";
else
if (igrade[j] < 80)
cout << "\nStudent has a GRADE B\n\n";
else
if (igrade[j] >= 80)
cout << "\nStudent has a GRADE A\n\n";
cout << "---------------------------\n";

j++;


cout << "\n\nTo quit, press Q or enter another grade to continue\n";
cin >> keypress;
system("cls");
}
return 0;
}


[Edited on 27-10-2006 by Reedy]


Ren

posted on 27th Oct 06 at 12:03

yeah, one after another if you get what i mean


jaffa

posted on 27th Oct 06 at 12:00

quote:
Originally posted by Ren
Normally, when i'd do a while loop, the next set of calculations would be done directly under the ones you had just done. With this code, it removes what was there, and replaces it with the new solution.

Normally this wouldnt matter, but i need to see multiple grades for my assigment.


so you need to display all results entered?


Steve

posted on 27th Oct 06 at 11:57

i was saying the question you asked seemed to be more of a maths question than a programming one


Ren

posted on 27th Oct 06 at 11:56

quote:
Originally posted by Steve
quote:
Originally posted by Ren
Well you didnt even attempt to help me out, and instead critisised my coding. So yeah :boggle:


where did i criticise your code :boggle:


When you said i need to sort out my maths, i just assumed you were taking a dig :|


Ren

posted on 27th Oct 06 at 11:56

Normally, when i'd do a while loop, the next set of calculations would be done directly under the ones you had just done. With this code, it removes what was there, and replaces it with the new solution.

Normally this wouldnt matter, but i need to see multiple grades for my assigment.


Steve

posted on 27th Oct 06 at 11:55

quote:
Originally posted by Ren
Well you didnt even attempt to help me out, and instead critisised my coding. So yeah :boggle:


where did i criticise your code :boggle:


jaffa

posted on 27th Oct 06 at 11:47

whats not working?


Ren

posted on 27th Oct 06 at 11:31

Well you didnt even attempt to help me out, and instead critisised my coding. So yeah :boggle:


Steve

posted on 27th Oct 06 at 11:24

does it seem like a twattish remark?


Ren

posted on 27th Oct 06 at 11:23

Was that supposed to be a twattish remark?


Steve

posted on 27th Oct 06 at 11:17

it seems like you need to work out the math formula rather than the programming language itself


Ren

Icon depicting mood of post posted on 27th Oct 06 at 11:16

(C++)

I'm writing a program that converts numbers input to the program into grades in a simple fashion. I have everything sorted, all the coding is fine, all the formula's are right except one... Im trying to make it so after a grade has been given, the program contunues after for the next number to convert to a grade - but right now it'll delete what was already there and start afresh.

Here's the code anyway:
#include <iostream>
#include <conio.h>

int main()
{
int igrade =0;
char keypress;

while (keypress!='q')
{
std::cout << "# STUDENT GRADE PROGRAM #\n";
std::cout << "---------------------------\n";
std::cout << "Please enter Student Grade \n";
std::cin >> igrade;

//Formula for converting numbers to grades
if (igrade < 40)
std::cout << "\nStudent Has FAILED\n\n";
else
if (igrade < 60)
std::cout << "\nStudent Has a GRADE C\n\n";
else
if (igrade < 80)
std::cout << "\nStudent has a GRADE B\n\n";
else
if (igrade >= 80)
std::cout << "\nStudent has a GRADE A\n\n";
std::cout << "---------------------------\n";


std::cout << "\n\nTo quit, press Q or enter another grade to continue\n";
keypress=getch();
system("cls");
}
return 0;
}

Anyhelp anyone? :thumbs:

[Edited on 27-10-2006 by Ren]