just
int array [3], t;
to
int array [10], t;
just
int array [3], t;
to
int array [10], t;
i have this code which input 3 numbers into ascending order. i know make it 10 i just change the array size but then it is only ascending the numbers that were inputing that are under 10. how can i change it so it's any number.
#include <iostream>
#include <conio.h>
using namespace std;
int main ()
{ int x;
int array [3], t;
for (x=0; x<3; x++)
{
cout << "Enter integer number: " << endl;
cin >> array[x];
}
for (x=0; x<3; x++)
{
for (int y=0; y<2; y++)
{
if(array[y]>array[y+1])
{
t=array[y];
array[y]=array[y+1];
array[y+1]=t;
}
}
}
cout << "The integers in ascending order are : ";
for (x=0;x<3;x++)
{
cout <<"\n";
cout <<array[x];
cout << "\n";
}
system ("pause");
return 0;
}
i have this code here which inputs the numbers and then adds them. is there a cheats way i can change it so that it inputs the numbers then puts them into ascending order.
#include <iostream.h>
void getNumber(int &, int);
void sum( int, int &);
void output(int[ ], int, int);
int main()
{
const int SIZE = 10;
int array[SIZE] = {0};
int total = 0;
for ( int i = 0; i < SIZE; i++)
{
getNumber(array[i], i + 1);
sum( array[i], total);
}
output(array, total, SIZE);
}void getNumber(int &num, int numCount)
{
cout << "Enter number " << numCount << ":";
cin >> num;
}
void sum(int num, int &total)
{
total += num;
}
void output(int array[ ], int total, int arraySize)
{
cout << "The sum of ";
for (int i = 0; i < arraySize; i++)
{
cout << array[i] ;
if( i < arraySize - 1)
cout << " + ";
}
cout << " is " << total << endl;
system ("pause");
}
i've fixed it now.
#include <iostream.h>
void readThreeNumbers(int &, int &, int &);
void sortThreeNumbers(int &, int &, int &);
void displayNumbers(int, int, int);
int main()
{
int number1, number2, number3;
readThreeNumbers(number1, number2, number3);
sortThreeNumbers(number1, number2, number3);
displayNumbers(number1, number2, number3);
}
void readThreeNumbers(int &number1, int &number2, int &number3)
{
cout << "Enter three numbers, with a space between them: ";
cin >> number1 >> number2 >> number3;
}
void sortThreeNumbers(int &number1, int &number2, int &number3)
{
int temp;
if (number1 > number2)
{
temp = number1;
number1 = number2;
number2 = temp;
}
if (number2 > number3)
{
temp = number2;
number2 = number3;
number3 = temp;
}
if (number1 > number2)
{
temp = number1;
number1 = number2;
number2 = temp;
}
}
void displayNumbers(int number1, int number2, int number3)
{
cout << "\nThe numbers sorted in ascending order are\n"
<< number1 << endl
<< number2 << endl
<< number3 << endl;
system ("pause");
}
ok this is it now
#include<iostream>
#include<iomanip>
using namespace std;
void readThreeNumbers(float number1,float number2,float number3);
void sortThreeNumbers(float number1,float number2,float number3);
void displayNumbers(float number1,float number2,float number3);
int main ()
{
float number1, number2, number3;
readThreeNumbers(number1, number2, number3)
{
cout << "Please enter three floating-point numbers, space between them: ";
cin >> number1 >> number2 >> number3;
}
sortThreeNumbers(number1, number2, number3)
{
if (number1 > number2)
{
temp = number1
number1 = number2
number2 = temp
}
if (number2 > number3)
{
temp = number2
number2 = number3
number3 = temp
}
if (number1 > number2)
{
temp = number1
number1 = number2
number2 = temp
}
}
void displayNumbers(number1, number2, number3)
{
cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2);
cout << "The average of " << number1 << "," << number2 << " and " << number3 << " is " << ;
system("pause");
}
but now im getting a lot of syntax errors
line:
14. expected `;' before '{' token
19. expected `;' before '{' token
40. expected `;' before '{' token
44. expected `}' at end of input
#include<iostream.h>
#include<iomanip.h>
using namespace std;
float number1, number2, number3;
void readThreeNumbers(number1, number2, number3);
void sortThreeNumbers(number1, number2, number3);
void displayNumbers(number1, number2, number3);
int main ()
{
readThreeNumbers(number1, number2, number3);
sortThreeNumbers(number1, number2, number3);
displayNumbers(number1, number2, number3);
}
void readThreeNumbers(number1, number2, number3)
{
cout << "Please enter three floating-point numbers, space between them: ";
cin >> number1 >> number2 >> number3;
}
void sortThreeNumbers(number1, number2, number3)
{
if (number1 > number2)
{
temp = number1
number1 = number2
number2 = temp
}
if (number2 > number3)
{
temp = number2
number2 = number3
number3 = temp
}
if (number1 > number2)
{
temp = number1
number1 = number2
number2 = temp
}
}
void displayNumbers(number1, number2, number3)
{
cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2);
cout << "The average of " << number1 << "," << number2 << " and " << number3 << " is " << ;
system("pause");
}
i have this code that which inputs three number sort the three numbers in
ascending order then output the three numbers.
i'm getting this list of errors but i don't know how fix it.
In function `int main()':
`readThreeNumbers' cannot be used as a function
`sortThreeNumbers' cannot be used as a function
`displayNumbers' cannot be used as a function
At global scope:
`readThreeNumbers' declared void
`int readThreeNumbers'
`int readThreeNumbers' previously declared here
expected `,' or `;' before '{' token
`sortThreeNumbers' declared void
redefinition of `int sortThreeNumbers'
`int …
#include<iostream.h>
#include<iomanip.h>
using namespace std;
enum ComponentTypes = { CT_TELEVISION, CT_VIDEORECORDER, CT_CAMERA, CT_DVD, CT_HIFISTEREO, CT_VIDEOCD, CT_LAST };
int CT_LAST = 0;
string names[CT_LAST] = { "Televisions", "Video Recorder","Camera","DVD","HIFI Stereo","Video CD" };
int quantities[CT_LAST];
int prices[CT_LAST];
int totalStockValue [CT_LAST];
int main()
{
for (int a = 0; a < CT_LAST; ++a)
{
cout << "Input the price of the " << names[a] << ": ";
cin >> prices[a];
}
for (int b = 0; b < CT_LAST; ++b)
{
cout << "Input the quantity of the " << names[b] << ": ";
cin >> quantities[b];
}
cout<<setiosflags(ios::fixed)<<setprecision(2);
cout<<setiosflags(ios::fixed)<<setprecision(2);
cout<<setiosflags(ios::fixed)<<setprecision(2);
cout<<setw(15)<< "Item" //fomats the output
<<setw(11)<< "Quantity"
<<setw(13)<< "Unit Price"
<<setw(14)<< "Total Value"<<endl;
cout<<"============================================================="<<endl;
cout<<setw(15)<< "Television"
<<setw(11)<< quantities[CT_TELEVISION]/*when i tried this it didn't work because it said undeclared, what do i write in here*/
<<setw(13)<< prices[CT_TELEVISION]
<<setw(14)<< endl;
cout<<setw(15)<< "Video Recorder"
<<setw(11)<< quantities[CT_VIDEORECORDER]
<<setw(13)<< prices[CT_VIDEORECORDER]
<<setw(14)<< endl;
cout<<setw(15)<< "Camera"
<<setw(11)<< quantities[CT_CAMERA]
<<setw(13)<< prices[CT_CAMERA]
<<setw(14)<< endl;
cout<<setw(15)<< "DVD"
<<setw(11)<< quantities[CT_DVD]
<<setw(13)<< prices[CT_DVD]
<<setw(14)<< endl;
cout<<setw(15)<< "HiFi Stereo"
<<setw(11)<< quantities[CT_HIFISTEREO]
<<setw(13)<< prices[CT_HIFISTEREO]
<<setw(14)<< endl;
cout<<setw(15)<< "Video CD"
<<setw(11)<< quantities[CT_VIDEOCD]
<<setw(13)<< prices[CT_VIDEOCD]
<<setw(14)<< endl;
cout<<"============================================================="<<endl;
system("pause");
}
ok this is my code now
#include<iostream.h> //is used so it will display output to the user and that input can be read from the keyboard
#include<iomanip.h> //is used so that the user can format input
using namespace std;
void getQuanity(int&,int);
void getStock(int, int&);
void gross(int[],int,int);
int main()
{
int ComponentTypes = 0;
int names = 0;
int prices = 0;
int quantities =0;
enum ComponentTypes = { CT_TELEVISION, CT_VIDEORECORDER, CT_CAMERA, CT_DVD, CT_HIFISTEREO, CT_VIDEOCD, CT_LAST };
string names[CT_LAST] = { "Televisions", "Video Recorder","Camera","DVD","HIFI Stereo","Video CD" };
int quantities[CT_LAST];
int prices[CT_LAST];
for (int a = 0; a < CT_LAST; ++a)
{
cout << "Input the price of the " << names[a] << ": ";
cin >> prices[a];
}
for (int b = 0; b < CT_LAST; ++b)
{
cout << "Input the quantity of the " << names[b] << ": ";
cin >> prices[b];
}
float totalStockValue1 = qty1 * price1; //the equation that calculates the price of the item multipled by the quantity
float totalStockValue2 = qty2 * price2;
float totalStockValue3 = qty3 * price3;
float totalStockValue4 = qty4 * price4;
float totalStockValue5 = qty5 * price5;
float totalStockValue6 = qty6 * price6;
float totalGrossValue = totalStockValue1 + totalStockValue2 + totalStockValue3 + totalStockValue4 + totalStockValue5 + totalStockValue6; //calculates the total value of all the inputs
cout<<setiosflags(ios::fixed)<<setprecision(2); //sets the output to 2 decimal places
cout<<setiosflags(ios::fixed)<<setprecision(2);
cout<<setiosflags(ios::fixed)<<setprecision(2);
cout<<setw(15)<< "Item" //fomats the output
<<setw(11)<< "Quantity"
<<setw(13)<< "Unit Price"
<<setw(14)<< "Total Value"<<endl;
cout<<"============================================================="<<endl;
cout<<setw(15)<< "Television"
<<setw(11)<< qty1
<<setw(13)<< price1
<<setw(14)<< totalStockValue1<<endl;
cout<<setw(15)<< "Video …
im getting this error use of enum `ComponentTypes' without previous declaration
where do i declare it.
ok i understand that but where do i put it in the code.
and how do i write it before each question.
#include<iostream.h> //is used so it will display output to the user and that input can be read from the keyboard
#include<iomanip.h> //is used so that the user can format input
using namespace std;
int main()
{
int qty1;
cout << "Please enter the quantity of Televisions: "<<endl;
cin >> qty1;
int qty2;
cout << "Please enter the quantity of Video Recorder: "<<endl;
cin >> qty2;
int qty3;
cout << "Please enter the quantity of Camera: "<<endl;
cin >> qty3;
int qty4;
cout << "Please enter the quantity of DVD: "<<endl;
cin >> qty4;
int qty5;
cout << "Please enter the quantity of HiFi Stereo: "<<endl;
cin >> qty5;
int qty6;
cout << "Please enter the quantity of Video CD: " <<endl;
cin >> qty6;
int price1;
cout << "Please enter the price of Televisions: "<<endl;
cin >> price1;
int price2;
cout << "Please enter the price of Video Recorder: "<<endl;
cin >> price2;
int price3;
cout << "Please enter the price of Camera: "<<endl;
cin >> price3;
int price4;
cout << "Please enter the price of DVD: "<<endl;
cin >> price4;
int price5;
cout << "Please enter the price of HiFi Stereo: "<<endl;
cin >> price5;
int price6;
cout << "Please enter the price of Video CD: " <<endl;
cin >> price6;
float totalStockValue1 = qty1 * price1; //the equation that calculates the price of the item multipled by the quantity
float totalStockValue2 = qty2 * price2;
float totalStockValue3 = qty3 * price3;
float totalStockValue4 = qty4 * price4; …
ok so i got rid of the for loop realised it was useless.
#include<iostream.h> //is used so it will display output to the user and that input can be read from the keyboard
#include<iomanip.h> //is used so that the user can format input
using namespace std;
void getQuanity(int&,int);
void getStock(int, int&);
void gross(int[],int,int);
int main()
{
int qty1;
cout << "Please enter the quantity of Televisions: "<<endl;
cin >> qty1;
int qty2;
cout << "Please enter the quantity of Video Recorder: "<<endl;
cin >> qty2;
int qty3;
cout << "Please enter the quantity of Camera: "<<endl;
cin >> qty3;
int qty4;
cout << "Please enter the quantity of DVD: "<<endl;
cin >> qty4;
int qty5;
cout << "Please enter the quantity of HiFi Stereo: "<<endl;
cin >> qty5;
int qty6;
cout << "Please enter the quantity of Video CD: " <<endl;
cin >> qty6;
int price1;
cout << "Please enter the price of Televisions: "<<endl;
cin >> price1;
int price2;
cout << "Please enter the price of Video Recorder: "<<endl;
cin >> price2;
int price3;
cout << "Please enter the price of Camera: "<<endl;
cin >> price3;
int price4;
cout << "Please enter the price of DVD: "<<endl;
cin >> price4;
int price5;
cout << "Please enter the price of HiFi Stereo: "<<endl;
cin >> price5;
int price6;
cout << "Please enter the price of Video CD: " <<endl;
cin >> price6;
float totalStockValue1 = qty1 * price1; //the equation that calculates the price of the item multipled by …
i can't put into words how much i thank you for helping me.
thank you for helping me so much. i have a bit of trouble. i know its excessive but i didnt know how to shorten it then make it work.
my compiler error list is:
'stockPrice' undeclared
'input' undeclared
'stockValue' undeclared
'computation' undeclared
'SIZE' undeclared
'item' undeclared
'getNumber' undeclared
'total' undeclared
'sum' undeclared
'output' undeclared
In function `void getNumber(int&, int)'
'void getNumber(int&, int)' used prior to declaration
'heading' undeclared
'qtyStock' undeclared
'stockPrice' undeclared
'stockValue' undeclared
'output' undeclared
'outputGross' undeclared
i changed what you said to this:
void getNumber(int &num, int numCount)
{
cout<<"Enter Number" << numCount<< ":";
cin>>num;
heading();
for(int m = 0; m < 6; m++)
{
output(qtyStock[m], stockPrice[m], stockValue[m], m);
}
outputGross(gross);
}
/*Alysha Jacobson
6351476*/
#include<iostream.h> //is used so it will display output to the user and that input can be read from the keyboard
#include<iomanip.h> //is used so that the user can format input
using namespace std;
void getQuanity(int&,int);
void getStock(int, int&);
void gross(int[],int,int);
int main()
{
int qty1;
cout << "Please enter the quantity of Televisions: "<<endl;
cin >> qty1;
int qty2;
cout << "Please enter the quantity of Video Recorder: "<<endl;
cin >> qty2;
int qty3;
cout << "Please enter the quantity of Camera: "<<endl;
cin >> qty3;
int qty4;
cout << "Please enter the quantity of DVD: "<<endl;
cin >> qty4;
int qty5;
cout << "Please enter the quantity of HiFi Stereo: "<<endl;
cin >> qty5;
int qty6;
cout << "Please enter the quantity of Video CD: " <<endl;
cin >> qty6;
int price1;
cout << "Please enter the quantity of Televisions: "<<endl;
cin >> price1;
int price2;
cout << "Please enter the quantity of Video Recorder: "<<endl;
cin >> price2;
int price3;
cout << "Please enter the quantity of Camera: "<<endl;
cin >> price3;
int price4;
cout << "Please enter the quantity of DVD: "<<endl;
cin >> price4;
int price5;
cout << "Please enter the quantity of HiFi Stereo: "<<endl;
cin >> price5;
int price6;
cout << "Please enter the quantity of Video CD: " <<endl;
cin >> price6;
float totalStockValue1 = qty1 * price1; //the equation that calculates the price of the item multipled by the quantity
float totalStockValue2 = qty2 * price2;
float totalStockValue3 …
You need a variable or array to get the Quantity and Sum
does that mean i need to put
int quantity =0
int sum = 0
after int total =0?
the most i need help with is declaring Television, VideoRecorder, Camera, DVD, HiFiStereo, VideoCD. i think once i have those declared i can fix the rest.
i have an assignment due for my c++ class where we have to input from the keyboard the quantity and input from the keyboard the stock price.
so that it outputs as:
Stock Item Quantity Unit Price Total Value
----------------------------------------------
Television 5 368.00 1840.00
Video Recorder 8 268.00 2144.00
Camera 9 300.00 2700.00
DVD 10 468.00 4680.00
Hi Fi Stereo 13 2500.00 32500.00
Video CD 25 345.00 8625.00
----------------------------------------------
Gross Total: 52489.00
this is the code i have so far. i know i need to declare everything but i don't know how or where i should put it if any one has any advice that would be helpful. i hope i've given all the information you need.
#include<iostream.h> //is used so it will display output to the user and that input can be read from the keyboard
#include<iomanip.h> //is used so that the user can format input
using namespace std;
void getQuanity(int&,int);
void getStock(int, int&);
void gross(int[],int,int);
int main()
{
int item [6] = { Television, VideoRecorder, Camera, DVD, HiFiStereo, VideoCD };
int total = 0;
cout<<setiosflags(ios::fixed)<<setprecision(2); //sets the output to 2 decimal places
cout<<setiosflags(ios::fixed)<<setprecision(2);
cout<<setiosflags(ios::fixed)<<setprecision(2);
cout<<setw(15)<< "Item" //fomats the output
<<setw(11)<< "Quantity"
<<setw(13)<< "Unit Price"
<<setw(14)<< "Total Value"<<endl;
cout<<"============================================================="<<endl;
cout<<setw(15)<< "Television"
<<setw(11)<< qty1
<<setw(13)<< price1
<<setw(14)<< totalStockValue1<<endl;
cout<<setw(15)<< "Video Recorder"
<<setw(11)<< qty2
<<setw(13)<< price2
<<setw(14)<< totalStockValue2<<endl;
cout<<setw(15)<< "Camera"
<<setw(11)<< qty3
<<setw(13)<< price3
<<setw(14)<< totalStockValue3<<endl;
cout<<setw(15)<< "DVD"
<<setw(11)<< qty4
<<setw(13)<< price4
<<setw(14)<< totalStockValue4<<endl;
cout<<setw(15)<< "HiFi Stereo"
<<setw(11)<< …
yerp thats it! thanks so much
a) INT
b) my-name
c) your_name
d) $dollar
e) stock Price
f) _UnitPrice
g) while
h) 1$dollar
i) switch
j) whileYou
k) ifYou
l) if
m) int
n) int34
o) ab.3c
p) ab_3c
q) 4%6
r) fourTimesSix
s) 4 * 6
t) apples3
Can you give a specific example of the task or better explain the problem narratively?
The word table when used in the context of C++ frequently refers to a 2 dimensional array of values and your code implements an algorhithm to accumulate value in variable called sum by adding the value of c to sum each time through the loop, so I suspect you might want to be writing code to walk through a table of values adding the value of each item in the table to generate a total value of all elements in the table. But then again I could be way of base, too.
This is how the question was given and next to it was a table with 3 columns and some amount of rows and i know your ment to go through each step that it would take to work out the final value.
Q1. Given the code below:-
int c = 0, sum = 0;
while (sum < 8)
{
c++;
sum += c;
}
cout << sum;
What is the final value of sum when the loop terminates? (1 mark)
Use the walkthrough table above.
a) 8
b) 9
c) 10
d) 11
This is the only example I could find on it and I don't really understand it.
http://i129.photobucket.com/albums/p213/momanrox/deskcheck.jpg?t=1273802928
i have this code and for an class work task and you have to do a walkthrough table and work out the output. But i dont know how you do a walkthrough table. Can someone help?
int c = 0, sum = 0;
while (sum < 8)
{
c++;
sum += c;
}
cout << sum;
:)
its a random number generator
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#include <iomanip.h>
using namespace std;
int main ()
{
const int MAX_RANGE = 100;
int value;
int random = rand( );
int num = ((random % 100) + 1);
int quit;
do
{
srand (time (NULL));
value = rand() % MAX_RANGE + 1;
cout << value<<endl;
cout << "Enter 0 to end program: ";
cout << "Guess a number between 1 and 100: ";
cin >> value;
if (value > num)
{
cout << "The number is lower. Try Again\n";
}
if (value < num)
{
cout << "The number is higher. Try Again\n";
}
else if (value == num)
{
cout << "You've guessed correctly\n";
system ("pause");
cin >> quit;
}
while (quit != 0);
}