Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Anyone know C+ and have an hour to spare?
New Posts  All Forums:Forum Nav:

Anyone know C+ and have an hour to spare?

post #1 of 13
Thread Starter 
I'm doing some codelab C++ homework and I keep getting stuck. It isn't like writing an entire program or anything. Just 1 or 2 lines of code max per problem.

I'm asking u to get on an IM client with me and do the problems with me.

Example problems:

1- Write the definition of a function printLarger , which has two int parameters and returns nothing. The function prints the larger value of the two parameters to standard output on a single line by itself.

2- Write the definition of a function twice , that receives an integer parameter and returns an integer that is twice the value of that parameter.

3- Write the definition of a function add , which receives two integer parameters and returns their sum.

4- Assume that an array of int named a has been declared with 12 elements and that the integer variable k holds a value between 0 and 6.

Assign 15 to the array element whose index is k .

Monetary compensation will be given.
Edited by MeeMoo220 - 3/28/11 at 7:50pm
post #2 of 13
Quote:
Originally Posted by MeeMoo220;12909734 
1- Write the definition of a function printLarger , which has two int parameters and returns nothing. The function prints the larger value of the two parameters to standard output on a single line by itself.

void printLarger(int x, int y)
{
//open outfile
if (x <= y ){
//write y to outfile, you had to do this on the last one I help you with
}
else{
//write x to outfile, you had to do this on the last one I help you with
}
//close outfile
}
Quote:
Originally Posted by MeeMoo220;12909734 
2- Write the definition of a function twice , that receives an integer parameter and returns an integer that is twice the value of that parameter.

int twice( int x)
{
x = 2*x;
return x;
}
Quote:
Originally Posted by MeeMoo220;12909734 
3- Write the definition of a function add , which receives two integer parameters and returns their sum.

int sum(int x, int y)
{
int z = x + y;
return z;
}


No monetary compensation needed.
I Love Cheese
(13 items)
 
  
CPUMotherboardGraphicsRAM
2600k @ 3.4 Asus P8P67 Basic XFX 5970 2 gig Black Edition 2x 4 gig DDR 1600 G-Skill 
Hard DriveOSMonitorPower
2x500 gig WD Vista Ultimate 64-bit Dual 25" Hannspree LCD CM 750 Watt 
CaseMouse
Rosewill THOR Logitech Trackball 
  hide details  
Reply
I Love Cheese
(13 items)
 
  
CPUMotherboardGraphicsRAM
2600k @ 3.4 Asus P8P67 Basic XFX 5970 2 gig Black Edition 2x 4 gig DDR 1600 G-Skill 
Hard DriveOSMonitorPower
2x500 gig WD Vista Ultimate 64-bit Dual 25" Hannspree LCD CM 750 Watt 
CaseMouse
Rosewill THOR Logitech Trackball 
  hide details  
Reply
post #3 of 13
Thread Starter 
Quote:
Originally Posted by joemaniaci;12909868 
void printLarger(int x, int y)
{
//open outfile
if (x <= y ){
//write y to outfile, you had to do this on the last one I help you with
}
else{
//write x to outfile, you had to do this on the last one I help you with
}
//close outfile
}



int twice( int x)
{
x = 2*x;
return x;
}



int sum(int x, int y)
{
int z = x + y;
return z;
}


No monetary compensation needed.

Well, thanks for that, Joe. however, the reason I need help is that this program is retarded.

Here's what it said.

logical error:

Remarks:
*****⇒*****You are not displaying anything on the screen.
Remarks:
*****⇒*****Checking output.


EDIT: don't know what the hel it's censoring. They're just spaces.
post #4 of 13
iirc, aren't you using microsoft visual studios for this class?

it could be that twice and sum are returning a value, but they might not be returning the value to anything.

What you need to do is to declare more integers in your main program, x and y again, so you can do this.

int x;
int y;

x = sum(first_int, second_int);
y = twice(only_int);
I Love Cheese
(13 items)
 
  
CPUMotherboardGraphicsRAM
2600k @ 3.4 Asus P8P67 Basic XFX 5970 2 gig Black Edition 2x 4 gig DDR 1600 G-Skill 
Hard DriveOSMonitorPower
2x500 gig WD Vista Ultimate 64-bit Dual 25" Hannspree LCD CM 750 Watt 
CaseMouse
Rosewill THOR Logitech Trackball 
  hide details  
Reply
I Love Cheese
(13 items)
 
  
CPUMotherboardGraphicsRAM
2600k @ 3.4 Asus P8P67 Basic XFX 5970 2 gig Black Edition 2x 4 gig DDR 1600 G-Skill 
Hard DriveOSMonitorPower
2x500 gig WD Vista Ultimate 64-bit Dual 25" Hannspree LCD CM 750 Watt 
CaseMouse
Rosewill THOR Logitech Trackball 
  hide details  
Reply
post #5 of 13
Thread Starter 
Quote:
Originally Posted by joemaniaci;12909923 
iirc, aren't you using microsoft visual studios for this class?

We use Bloodshed Dev C++, however, for these exercises, we use this stupid website called codelab. It makes the teacher's job easier and our lives hell.

EDIT: it uses it's own compiler and gives uremarks and suggestions. hardly ever useful.
post #6 of 13
Can you maybe take a screen shot of what you are working with?
I Love Cheese
(13 items)
 
  
CPUMotherboardGraphicsRAM
2600k @ 3.4 Asus P8P67 Basic XFX 5970 2 gig Black Edition 2x 4 gig DDR 1600 G-Skill 
Hard DriveOSMonitorPower
2x500 gig WD Vista Ultimate 64-bit Dual 25" Hannspree LCD CM 750 Watt 
CaseMouse
Rosewill THOR Logitech Trackball 
  hide details  
Reply
I Love Cheese
(13 items)
 
  
CPUMotherboardGraphicsRAM
2600k @ 3.4 Asus P8P67 Basic XFX 5970 2 gig Black Edition 2x 4 gig DDR 1600 G-Skill 
Hard DriveOSMonitorPower
2x500 gig WD Vista Ultimate 64-bit Dual 25" Hannspree LCD CM 750 Watt 
CaseMouse
Rosewill THOR Logitech Trackball 
  hide details  
Reply
post #7 of 13
Thread Starter 
Quote:
Assume that an array of int named a has been declared with 12 elements and that the integer variable k holds a value between 0 and 6.

Assign 15 to the array element whose index is k.

if (a[k]=<6 && a[k]=>0);
a[k]=15;

Am I doing it wrong?
post #8 of 13
Thread Starter 
Quote:
Originally Posted by joemaniaci;12910058 
Can you maybe take a screen shot of what you are working with?

Here's what I see.
post #9 of 13
Thread Starter 
Quote:
Originally Posted by MeeMoo220;12910070 
if (a[k]=<6 && a[k]=>0);
a[k]=15;

Am I doing it wrong?

Yes. Apparently, this is the answer:

a[k]=15;
post #10 of 13
Quote:
Originally Posted by MeeMoo220;12910185 
Yes. Apparently, this is the answer:

a[k]=15;

Yeh, I was about to say, it couldn't be equal to both 0 and 6.
I Love Cheese
(13 items)
 
  
CPUMotherboardGraphicsRAM
2600k @ 3.4 Asus P8P67 Basic XFX 5970 2 gig Black Edition 2x 4 gig DDR 1600 G-Skill 
Hard DriveOSMonitorPower
2x500 gig WD Vista Ultimate 64-bit Dual 25" Hannspree LCD CM 750 Watt 
CaseMouse
Rosewill THOR Logitech Trackball 
  hide details  
Reply
I Love Cheese
(13 items)
 
  
CPUMotherboardGraphicsRAM
2600k @ 3.4 Asus P8P67 Basic XFX 5970 2 gig Black Edition 2x 4 gig DDR 1600 G-Skill 
Hard DriveOSMonitorPower
2x500 gig WD Vista Ultimate 64-bit Dual 25" Hannspree LCD CM 750 Watt 
CaseMouse
Rosewill THOR Logitech Trackball 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Anyone know C+ and have an hour to spare?