Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Can someone help me allign my project and see what im doing wrong?
New Posts  All Forums:Forum Nav:

Can someone help me allign my project and see what im doing wrong?

post #1 of 4
Thread Starter 
Hey guys below is my full code for this homework. I've gotten the code to function as it suppose to, however when it comes time to put it for display the Units column and Amount Column does not align correctly and im already fed up trying to figure out what am i doing wrong, is there someone who can pls help?


#include<iostream>
#include<iomanip>
using namespace std ;

int main(void)

{
float total = 0 ;
const int num = 5 ;
float price[num] = { 9.92, 6.32, 12.63, 5.95, 10.29 }, Units[num], Amount[num] ;
int i ;

cout<<"Price"<<setw(9)<<"Units"<<setw(10)<<"Amount "<<endl ;
cout<<"-----"<<setw(9)<<"-----"<<setw(10)<<"------"<<endl ;

for (i=0 ; i<num ; i++)

{

cout << price[i] << setw(11) << right ;
cin >> setw(20) >> Units[i] ; cout << setw(15);
Amount[i] = price[i] * Units[i] ; cout << setw(18) << Amount[i] << endl ;
total = total + Amount[i] ;

}

cout << setw(24) << "------" << endl ;
cout << "Total: " <<setw(17) << total << endl ;

return 0 ;
}
overclocking toy
(13 items)
 
  
CPUMotherboardGraphicsRAM
I7-950 Asus P6TD Deluxe MSI GTX 560 TI Corsair XMS3 12gb DDR3 
Hard DriveOptical DriveOSMonitor
1.5 TB @7200 RPM Blu-Ray/DVD/CD + Burner Windows 7 Asus 27" LED 
PowerCase
Corsair HX 850 Coolermaster HAF 932 
  hide details  
Reply
overclocking toy
(13 items)
 
  
CPUMotherboardGraphicsRAM
I7-950 Asus P6TD Deluxe MSI GTX 560 TI Corsair XMS3 12gb DDR3 
Hard DriveOptical DriveOSMonitor
1.5 TB @7200 RPM Blu-Ray/DVD/CD + Burner Windows 7 Asus 27" LED 
PowerCase
Corsair HX 850 Coolermaster HAF 932 
  hide details  
Reply
post #2 of 4
Use the Tab character ("\") to make things line up. Use serveral if something is especially long.

Example:
Code:
//Draw column headers
cout << "Price\Currency\Something Else";
//Show data
for(int i;;)
  cout << price[i] + "\" + currency[i] +"\" + something_else[i];
post #3 of 4
Quote:
Originally Posted by Aknolidge View Post
Hey guys below is my full code for this homework. I've gotten the code to function as it suppose to, however when it comes time to put it for display the Units column and Amount Column does not align correctly and im already fed up trying to figure out what am i doing wrong, is there someone who can pls help?


#include<iostream>
#include<iomanip>
using namespace std ;

int main(void)

{
float total = 0 ;
const int num = 5 ;
float price[num] = { 9.92, 6.32, 12.63, 5.95, 10.29 }, Units[num], Amount[num] ;
int i ;

cout<<"Price"<<setw(9)<<"Units"<<setw(10)<<"Amount "<<endl ;
cout<<"-----"<<setw(9)<<"-----"<<setw(9)<<"------"<<endl ;

for (i=0 ; i<num ; i++)

{

cout << price[i] << setw(11) << right ;
cin >> setw(20) >> Units[i] ; cout << setw(15);
Amount[i] = price[i] * Units[i] ; cout << setw(18) << Amount[i] << endl ;
total = total + Amount[i] ;

}

cout << setw(24) << "------" << endl ;
cout << "Total: " <<setw(17) << total << endl ;

return 0 ;
}
ok...i am almost done with your program...ill tell you what is wrong in a lil bit.
Edited by surfbumb - 4/22/11 at 11:12pm
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 10 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 10 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
post #4 of 4
here you go man...I put my heart and soul into this one...let me know what you think.

Code:
#include<iostream>
#include<iomanip>

using namespace std ;

int main(void)

{
double total = 0 ;
const int num = 5 ;
double price[num] = { 9.92, 6.32, 12.63, 5.95, 10.29 }; 
double units[num]; 
double amount[num];

for (int i = 0 ; i < num ; ++i){
printf("Price: %5.2lf", price[i]);
printf("    Enter number of units: ");
cin >> units[i];
amount[i] = units[i] * price[i];
total += amount[i];
}
cout << endl;
cout<<"Price"<<setw(9)<<"Units"<<setw(10)<<"Amount "<<endl ;
cout<<"-----"<<setw(9)<<"-----"<<setw(9)<<"------"<<endl ;

for (int i = 0 ; i < num ; ++i){

printf("%5.2lf %6.0lf %10.2lf \
" , price[i], units[i], amount[i]);
}

cout << setw(24) << "------" << endl ;
cout << "Total: " <<setw(17) << total << endl ;

return 0 ;
}
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 10 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 10 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  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 › Can someone help me allign my project and see what im doing wrong?