corsasport.co.uk
 

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


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author anyone good with programming? (geeks only)
Ren
Member

Registered: 16th Oct 04
User status: Offline
   27th Oct 06 at 11:16   View User's Profile U2U Member Reply With Quote

(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?

[Edited on 27-10-2006 by Ren]
Steve
Premium Member

Avatar

Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
27th Oct 06 at 11:17   View Garage View User's Profile U2U Member Reply With Quote

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

Registered: 16th Oct 04
User status: Offline
27th Oct 06 at 11:23   View User's Profile U2U Member Reply With Quote

Was that supposed to be a twattish remark?
Steve
Premium Member

Avatar

Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
27th Oct 06 at 11:24   View Garage View User's Profile U2U Member Reply With Quote

does it seem like a twattish remark?
Ren
Member

Registered: 16th Oct 04
User status: Offline
27th Oct 06 at 11:31   View User's Profile U2U Member Reply With Quote

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

Registered: 27th Mar 00
Location: Stoke-on-Trent
User status: Offline
27th Oct 06 at 11:47   View User's Profile U2U Member Reply With Quote

whats not working?
Steve
Premium Member

Avatar

Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
27th Oct 06 at 11:55   View Garage View User's Profile U2U Member Reply With Quote

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


where did i criticise your code
Ren
Member

Registered: 16th Oct 04
User status: Offline
27th Oct 06 at 11:56   View User's Profile U2U Member Reply With Quote

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.
Ren
Member

Registered: 16th Oct 04
User status: Offline
27th Oct 06 at 11:56   View User's Profile U2U Member Reply With Quote

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


where did i criticise your code


When you said i need to sort out my maths, i just assumed you were taking a dig
Steve
Premium Member

Avatar

Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
27th Oct 06 at 11:57   View Garage View User's Profile U2U Member Reply With Quote

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

Registered: 27th Mar 00
Location: Stoke-on-Trent
User status: Offline
27th Oct 06 at 12:00   View User's Profile U2U Member Reply With Quote

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?
Ren
Member

Registered: 16th Oct 04
User status: Offline
27th Oct 06 at 12:03   View User's Profile U2U Member Reply With Quote

yeah, one after another if you get what i mean
Reedy
Member

Registered: 11th Apr 04
Location: Hammersmith
User status: Offline
27th Oct 06 at 12:04   View User's Profile U2U Member Reply With Quote

#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]
Reedy
Member

Registered: 11th Apr 04
Location: Hammersmith
User status: Offline
27th Oct 06 at 12:06   View User's Profile U2U Member Reply With Quote

Also that is a quick bodge as such.

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

[Edited on 27-10-2006 by Reedy]
Reedy
Member

Registered: 11th Apr 04
Location: Hammersmith
User status: Offline
27th Oct 06 at 12:22   View User's Profile U2U Member Reply With Quote

try it now ive edited it and checked in visual stuido.
Ian
Site Administrator

Avatar

Registered: 28th Aug 99
Location: Liverpool
User status: Offline
27th Oct 06 at 15:26   View Garage View User's Profile U2U Member Reply With Quote

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
Member

Registered: 11th Apr 04
Location: Hammersmith
User status: Offline
27th Oct 06 at 15:32   View User's Profile U2U Member Reply With Quote

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

Avatar

Registered: 28th Aug 99
Location: Liverpool
User status: Offline
27th Oct 06 at 16:58   View Garage View User's Profile U2U Member Reply With Quote

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.
Ren
Member

Registered: 16th Oct 04
User status: Offline
27th Oct 06 at 17:01   View User's Profile U2U Member Reply With Quote

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
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
27th Oct 06 at 18:31   View User's Profile U2U Member Reply With Quote

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?

[Edited on 27-10-2006 by Ren]


Poor Code

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.
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
27th Oct 06 at 18:37   View User's Profile U2U Member Reply With Quote

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.

 
New Topic

New Poll

  Related Threads Author Forum Replies Views Last Post
Assembly Language... Jason Geek Day 36 2444
7th Nov 03 at 10:26
by Jason
 
"Progress" programming environment???? Mikorsa16v Geek Day 12 1226
23rd Jan 04 at 13:01
by Mikorsa16v
 
programming!!! topshot_2k Geek Day 0 837
21st Mar 05 at 13:36
by topshot_2k
 
Nakamishi headunits NovaGTE Help Zone, Modification and ICE Advice 29 2881
26th Oct 05 at 10:37
by Fear
 

Corsa Sport » Message Board » Off Day » Geek Day » anyone good with programming? (geeks only) 28 database queries in 0.0170510 seconds