Help stuck

icechef's Avatar, Join Date: Feb 2009
Go4Expert Member
Hi
Im trying to write a program that allows me to enter relevant infomation(shows on programme).
But now im stuck I want the user to be able to put there own info as many times as they state and then be able to display it.
Any help appreciated?
Thanks
Code:
#include"stdafx.h"//
#include<iostream.>//
#include<string.h>//
#include<sstream>
usingnamespace std; //
//------------------------------------------------------------------

class MB // Setting for creating Motherboard class.
{
public: // Constructors Public.
MB(char * , longdouble, float); // Define programs parameters.
void show_MB(void); // 
private: // Constructors private.
char MBP [25]; // Required specification.
longdouble MBM; // Required specification.
float MBR; // Required specification.
};
//-------------------------------------------------------------------------
MB::MB(char * MBP, longdouble MBM, float MBR) // Order of sequence.
//-------------------------------------------------------------------------
{
strcpy(MB::MBP, MBP); // Relates to program within.
MB::MBM = MBM; // Relates to program within.
MB::MBR = MBR; // Relates to program within.
};
//-------------------------------------------------------------------
void MB::show_MB(void) 
{
cout << "Processor: " << MBP << endl; // Display.
cout << "Speed: " << MBM << " Mhz " << endl; // Display.
cout << "RAM: " << MBR << " GB " << endl; // Display.
};
//--------------------------------------------------------------------------------
class VC // Setting for creating Video Card class.
{
public: // Constructors Public.
VC(char *, int, int, float); // Define programs parameters.
void show_VC(void); //
private: // Constructors private.
char VCB [25]; // Required specification.
int VCX; // Required specification.
int VCY; // Required specification.
float VCM; // Required specification.
};
//------------------------------------------------------------------------------
VC::VC(char * VCB, int VCX, int VCY, float VCM) // Order of sequence.
//-----------------------------------------------------------------------------
{
strcpy(VC::VCB, VCB); // Relates to program within.
VC::VCX = VCX; // Relates to program within.
VC::VCY = VCY; // Relates to program within.
VC::VCM = VCM; // Relates to program within.
};
//-------------------------------------------------------------------------------
void VC::show_VC(void)
{
cout << "Brand: " << VCB << endl; // Display.
cout << "Display: " <<VCX<< " X " <<VCY<< endl; // Display.
cout << "RAM: " << VCM << " GB " << endl; // Display.
};
 
//--------------------------------------------------------------------------------
class COMPUTER : public MB, public VC // Setting for creating Computer class.
{
public: // Constructors Public.
COMPUTER(char *, int, float, char *, longdouble, float, char *, int, int, float); // Define programs parameters.
void show_COMPUTER(void);
private:
char B[25]; // Required specification.
int HD; // Required specification.
float P; // Required specification.
};
//-----------------------------------------------------------------------------------------------
COMPUTER::COMPUTER(char * B, int HD, float P, // A parameters.
char * MBP,longdouble MBM, float MBR, // MB parameters.
char * VCB, int VCX, int VCY, float VCM) // VC parameters.
: MB(MBP, MBM, MBR ), VC(VCB, VCX, VCY, VCM ) // Within A Parameters.
//-------------------------------------------------------------------------------------------------
{
strcpy(COMPUTER::B, B); // Relates to program within.
COMPUTER::HD = HD; // Relates to program within.
COMPUTER::P = P; // Relates to program within.
MB (MBP,MBM,MBR); // Relates to program within.
VC (VCB,VCX,VCY,VCM); // Relates to program within.
}
//----------------------------------------------------------------------------------------
void COMPUTER::show_COMPUTER(void)
{
cout << "Brand: " << B << endl;
cout << "Hard disk: " << HD << " Gb" << endl;
cout << "Price: " << P << endl;
show_MB();
show_VC();
}
//void main(void)
//-----------------------------------------------------------------------------------------------
int main () // This is where the program starts it execution. It’s also the main function
{{
char B, MBP, VCB [25];
int HD, P, MBR, MBM, VCX, VCY, VCR;
int X, Y; // Defines variables
 
//--------------------------------------------------------------------------------------------------------------------------------
cout << "Enter number of computer sprecifications required? "; // Displays A Task Title
cin >> X; // Stores Entered Values
for ( Y=X; Y>=X; Y--); // Starts repeating statemen

//--------------------------------------------------------------------------------------------------------------------------------
{{{{{{{{{{
cout << "Please Enter Brand? "; // Displays A Task Title
cin >> B; // Stores Entered Values
cout << "Please Enter Hardrive Size? "; // Displays A Task Title
cin >> HD; // Stores Entered Values
cout << "Please Enter Price? "; // Displays A Task Title
cin >> P; // Stores Entered Values
cout << "Please Enter Processor? "; // Displays A Task Title
cin >> MBP; // Stores Entered Values
cout << "Please Enter Motherboard RAM? "; // Displays A Task Title
cin >> MBR; // Stores Entered Values
cout << "Please Enter Motherboard Memory? "; // Displays A Task Title
cin >> MBM; // Stores Entered Values
cout << "Please Enter Graphics Card Brand? "; // Displays A Task Title
cin >> VCB; // Stores Entered Values
cout << "Please Enter X Display? "; // Displays A Task Title
cin >> VCX; // Stores Entered Values
cout << "Please Enter Y Display? "; // Displays A Task Title
cin >> VCY; // Stores Entered Values
cout << "Please Enter Video Card RAM? "; // Displays A Task Title
cin >> VCR; // Stores Entered Values
}}}}}}}}}};
//-----------------------------------------------------------------------------------
{ 
COMPUTER PC("B", HD, P, "MBP", MBR, MBM, "VCB", VCX, VCY, VCR); PC.show_COMPUTER(); 
//return(0);
}}
system("pause>nul"); 
};
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Doesn't it already do that? What does it do if you enter 3 at "Enter number of computer sprecifications required?"; after you've entered the first details it looks like it should loop back to "Please Enter Brand?", although it's not so easy to tell with your brace abuse and lack of indentation.

Here's how braces and indentation are supposed to work:
Code:
somecode();
for(some;loop;stuff)
{
    loop();
    code();
}
This is much clearer than
Code:
somecode();
for(some;loop;stuff)
{{{{{{{{{{{{{{{{{{{{{{{{
loop();
code();
}}}}}}}}}}}}}}}}}}}}}}}}
and once you start getting into proper programming with multiple nested code blocks you'll find your current style extremely difficult to read. Programming's already hard enough, why make it harder?
icechef's Avatar, Join Date: Feb 2009
Go4Expert Member
Yeah it should loop but wont will try what you have said. Also I have found that there are 3 inputs that I have specifed as characters. but when unputed it causes the program to complete to the end. Any ideas?
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Exactly what input do you give and what output do you get?
If you run the program and copy and paste from the window directly into the edit box here that's probably the easiest and most accurate way.
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Oh hang on...just have another quick look at this line:
Code:
for ( Y=X; Y>=X; Y--);
There are several things wrong with this line. Try it in a small test program and see if you can find them all, e.g.
Code:
int main()
{
  int X=10, Y;
  for ( Y=X; Y>=X; Y--);
  {
    printf("%d\n",Y);
  }
  return 0;
}
(edit: thought I'd better indent as per my own advice)
icechef's Avatar, Join Date: Feb 2009
Go4Expert Member
Quote:
Originally Posted by xpi0t0s View Post
Doesn't it already do that? What does it do if you enter 3 at "Enter number of computer sprecifications required?"; after you've entered the first details it looks like it should loop back to "Please Enter Brand?", although it's not so easy to tell with your brace abuse and lack of indentation.

Here's how braces and indentation are supposed to work:
Code:
somecode();
for(some;loop;stuff)
{
    loop();
    code();
}
This is much clearer than
Code:
somecode();
for(some;loop;stuff)
{{{{{{{{{{{{{{{{{{{{{{{{
loop();
code();
}}}}}}}}}}}}}}}}}}}}}}}}
and once you start getting into proper programming with multiple nested code blocks you'll find your current style extremely difficult to read. Programming's already hard enough, why make it harder?
Hi, Sorry I have tried but am very new to this, any chance you could alter the code so it matches mine and will run! if I just then copy and paste.
Thank You
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
> any chance you could alter the code so it matches mine and will run!

No, sorry, just giving you the answer doesn't help you in any way. I'll give you pointers and help you solve problems. Programming is a skill learnt be doing not by looking at other people's complete code examples.

Best advice I can give you as a newcomer is to Keep It Simple, Stupid (KISS). Just get the minimum possible stuff working first, then extend afterwards. Even as a seasoned programmer of...hmm, 2009-1981=28 years! I still do this.

Besides I don't think you're actually that far off solving this. Just do the loop test I suggested and see if you can find all the problems with that line of code. I assume that the intent of your loop is to count down from X to 1, so the output should be 10 9 8 7 6 5 4 3 2 1, but what is it and how can you fix it so that it does that?

One thing worth knowing is that for (A; B; C) { D; } is equivalent to A; while (B) { D; C; } (yes, really D then C) so as an experiment you might try rewriting the for loop as a while loop.
icechef's Avatar, Join Date: Feb 2009
Go4Expert Member
Quote:
Originally Posted by xpi0t0s View Post
I assume that the intent of your loop is to count down from X to 1, so the output should be 10 9 8 7 6 5 4 3 2 1, but what is it and how can you fix it so that it does that?

One thing worth knowing is that for (A; B; C) { D; } is equivalent to A; while (B) { D; C; } (yes, really D then C) so as an experiment you might try rewriting the for loop as a while loop.
I need the loop so that the user defines homw lots of info required to input eg 5. then he can input the information into the relevant catorgory 5 times.
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Yes, I know what you need the loop for.
Did you try the small test that I suggested? If not, out of interest why not?
icechef's Avatar, Join Date: Feb 2009
Go4Expert Member
worked out what was wrong with loop now working changed it to this
(Y=0; Y<X; Y++)