• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

help with my C++ hw please??? should be easy for u guys

Smokey0066

Senior member
okay heres what i'm trying to do. I define a struct and then call a function to write to the struct then call another function to display whats in the struct.

Problem: i dont know how to reference struct in the function prototype; maybe i'm looking at this the wrong way.. anyone wanna straighten me out??

thanks.

CODE:

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <ctime>
using namespace std;

void readvalue(_____);
void showvalue(_____);

struct Quad
{
double a; double b; double c;
};
Quad read;
int main()
{
Quad read;

readvalue(_____);

showvalue(_____);

}

void readvalue(_____)
{
double w, e, r;
cout<<"Enter the coefficients a, b, c: ";
cin>>w >>e >>r;
cout<<w <<e <<r <<endl;
Quad read={w, e, r};
}

void showvalue(_____)
{
cout<<"The values entered are: " <<endl <<read.a <<endl <<read.b <<endl <<read.c <<endl;

}
 
forgot to mention that the functions should only have references to my Quad struct.

the more i think the more frustrated i get... GRRRR
 
Well im not fluent with C, but it seems to me that the most reasonable thing to do would be declare the struc frist, so the parameter list in your function prototype would be able to recognize any pointer of the struct type
 
I thought the assignment was in C? Why are you using C++? Here it is in C:

#include <stdio.h>


typedef struct QuadType
{
double a;
double b;
double c;
}Quad;



void ReadQuad(Quad *pQ);
void WriteQuad(Quad *pQ);



int main()
{
Quad quad;
ReadQuad(&quad);
WriteQuad(&quad);

return 0;
}



void ReadQuad(Quad *pQ)
{
printf("Enter co-efficients a, b, c: ");
scanf("%lf %lf %lf", &pQ->a, &pQ->b, &pQ->c);
}

void WriteQuad(Quad *pQ)
{
printf("\nCo-efficients are:\n");
printf("a = %f\n", pQ->a);
printf("b = %f\n", pQ->b);
printf("c = %f\n", pQ->c);
}


 
Originally posted by: Smokey0066
sorry.. c++ i thought you'd know from the code..

can you tell me how to do it in c++ thanks BTW

Here ya go:

#include <iostream.h>


struct Quad
{
double a;
double b;
double c;
};



void ReadQuad(Quad &q);
void WriteQuad(Quad &q);



int main()
{
Quad quad;
ReadQuad(quad);
WriteQuad(quad);

return 0;
}



void ReadQuad(Quad &q)
{
cout << "Enter co-efficients a, b, and c: ";
cin >> q.a >> q.b >> q.c;
}

void WriteQuad(Quad &q)
{
cout << "\nCo-efficients are:\n";
cout << "a = " << q.a << "\n";
cout << "a = " << q.b << "\n";
cout << "a = " << q.c << "\n";
}
 
Originally posted by: Smokey0066
THANKS ALOT.

taken a HUGE load off my back.. i was stuck on this for a long time..

thanks again..

smokey

No problem, but remember this is extremely simple and you have a long way to go in programming 🙂
 
hehe i'm only taking this because its a required class. i'm not very big into programing... just need to know enuff to get by.. hehe
 
Back
Top