i dunno, when i post my code on here it changes up.
Trust me i reformatted it. :p
Dinglish 0 Newbie Poster
ok, i have reformatted my code and sorted out my issue. For all those who were unhappy.
I now have a new problem, how would i output the commission value in case 4? (line 107).
here i have tried using
cout << "\n5% commission of total sales is " << commission = 0.05 * total_sales << "\n\n\n";
to assign commission a value, but i get the error
illegal use of floating point.
Any ideas?
Info :Compiling E:\program\kyeiassignforinternet.cpp
Warn : string.h(549,3):Functions containing for are not expanded inline
Warn : string.h(557,3):Functions containing while are not expanded inline
Warn : string.h(563,3):Functions containing for are not expanded inline
Warn : string.h(575,3):Functions containing for are not expanded inline
Warn : string.cc(686,32):Comparing signed and unsigned values
Warn : kyeiassignforinternet.cpp(14,10):Possible use of 'sales_amount' before definition
Warn : kyeiassignforinternet.cpp(14,10):Possible use of 'quantity' before definition
Warn : kyeiassignforinternet.cpp(15,16):Possible use of 'vat' before definition
Error: kyeiassignforinternet.cpp(90,103):Illegal use of floating point
Error: kyeiassignforinternet.cpp(92,104):Illegal use of floating point
Error: kyeiassignforinternet.cpp(94,104):Illegal use of floating point
Warn : kyeiassignforinternet.cpp(133,16):Use qualified name to access member type 'std::string'
oh yeah, here is my new and improved program:
#include <iostream> //the usual headers are used including string
#include <string>
#include <conio.h>
void WeeklySales(); //function i created
main()
{
int number; // declare variables
char answer;
double sales, sales_amount, quantity, total_sales, vat, commission;
sales = (sales_amount * quantity); //initialise variables
total_sales = (sales + vat);
commission …
Dinglish 0 Newbie Poster
No. If you post readable code, we can follow it. Please format your code cleanly and consistently. See this.
By not declaring them only during option 3. Once option 3 is done, the variables are destroyed. Define them at the beginning ofmain()
.
Then just post the relevant section of code. Then, no need to be sorry, and we don't have to search so much. :icon_wink:
thanks
Dinglish 0 Newbie Poster
i have a piece of an unfinished program.
try to run it...
if you go straight to option 3 and input values, how do i output these values in option 4 ?
i tried outputting my declared variables
it wont work ? why is this ?
i apologize the code is so long
I hope someone can tell me how i'd go about it
#include <iostream> //the usual headers are used including string
#include <string>
#include <conio.h>
void WeeklySales(); //these are functions i created
void yesnofunc();
main()
{
int number; // declare variables
char answer;
double sales, sales_amount, quantity, total_sales, vat, commission;
sales = (sales_amount * quantity); //initialise variables
total_sales = (sales + vat);
do { //start of a do-while loop
//output displays the menu
cout << "\n\n******Sales System******";
cout << ("\n\n");
cout << "1. Display Company Logo.\n"; endl;
cout << "2. Input/Validate weekly sales data.\n";endl;
cout << "3. Calculate weekly sales.\n";endl;
cout << "4. Display reciept.\n";endl;
cout << "5. SHUT DOWN & LOG OFF.\n";endl;
cout << "\nEnter a number...\n";endl; //prompts the user
cin >> number;
cout << ("\n\n");
switch (number) //<--the expression is a variable (number) & controls
//the switch the value of (number) is tested against a list of
//constants. When a match is found, the statement sequence
//assosciated with that match is executed.
{
case 1: //<----- const = 1
//displays the company logo
cout << "\n\tUU\tUU \tEEEEEEEE \tLL\t\t \SSSSSSS\n\tUU\tU";
cout << "U \tEE \t\tLL\t\tS\n\tUU\tUU \tEE \t\tLL\t\tS\n\t";
cout << "UU\tUU …
Dinglish 0 Newbie Poster
please run this simple program......
why wont this work ?
i tried it first with if...else
/*why will this program not run? what did i do wrong with the if else statements/conditions ?*/
#include <conio.h>
#include <iostream.h>
main()
{
double sales, sales_amount, quantity, total_sales, vat;
total_sales = sales + vat;
vat = 0.175*sales;
cout << "\nTotal Sales = sales amount * quantity\n"; endl;
cout << "\nEnter the sales amount\n";
cin >> sales_amount;
cout << "\nEnter the quantity\n" ;
cin >> quantity ;
sales = (sales_amount * quantity);
cout << "\n" << sales_amount << " * " << quantity << " = " << sales << "\n";
cout << "\n" << "Sales is: \t" << sales << "\n";
cout << "\ntotal sales inc VAT is: \t" << (sales + 0.175*sales) << "\n";
if (sales < 25) cout << "\nNo commission"; //<-------------why will this not run?
else if (50 > sales < 25) cout << "\n 5% commission " << total_sales * 0.05;
else if (75>sales<51) cout << "\n 10% commission "; << total_sales * 0.10;
else if (100>sales<76)cout << "\n 20% commission"; << total_sales * 0.20;
else cout << "20% commission" ;
getch();
}
i tried it with a switch statement
#include <conio.h>
#include <iostream.h>
main()
{
double sales, sales_amount, quantity, total_sales, vat;
total_sales = sales + vat;
vat = 0.175*sales;
cout << "\nTotal Sales = sales amount * quantity\n"; endl;
cout << "\nEnter the sales amount\n";
cin >> sales_amount;
cout << "\nEnter the quantity\n" ;
cin …
Dinglish 0 Newbie Poster
You have to use quantity with an index.quantity[x] for example.
if (quantity[x] < 1 || quantity[x] > 10)
ok caut_baia, i got it working now where the values are stored.
#include <iostream.h>
#include <conio.h>
main()
{
int quantity[10], x; //declare numbers[10] as an array and x as a counter
for(x=0; x<10; x++)
do
{
cout << ("\nPlease enter the quantity sold ");
cin >> quantity[x];
if (quantity[x] < 1 || quantity[x] > 10)
{
cout << ("\nINVALID QUANTITY. TRY A NUMBER FROM 1-10 \n");
}
}
while (quantity[x] < 1 || quantity[x] > 10);
getch();
}
it loops until the 10th value is entered.
but my program requires me to enter values one at a time along with values for other variables.
so after i enter the weekly sales data in my program below (please run) ie. id code, price and quantity, i want to be able to go back to the original menu and be able to enter more values if needed.
#include <iostream.h>
#include <string>
#include <conio.h>
void WeeklySales(); //we make weeklysales a function here too
void yesnofunc();
main()
{
int number;
do
{ //displays the menu
cout << "******Sales System******";
cout << ("\n\n");
cout << "1. Display Company Logo.\n"; endl;
cout << "2. Input/Validate weekly sales data.\n";endl;
cout << "3. Calculate weekly sales.\n";endl;
cout << "4. Display reciept.\n";endl;
cout << "5. SHUT DOWN & LOG OFF.\n";endl;
cout << "\nEnter number...\n";endl;
cin >> number;
cout << ("\n\n");
switch (number) //<--the expression is a variable …
Dinglish 0 Newbie Poster
@bugista.
because i have to write a pseudocode along with my program.
We also using borland 5.02. so alot of code that 95% progammers use are not recognised.
its a pain in the ...
Dinglish 0 Newbie Poster
To declare an array :
int numbers[10];[10] being the number of elements stored in the array
Numbers being the name of the arrayLet's say you have the numbers 1-10 stored in your array
To view all of these number, you can use a loopFirst declare a counter
int x;for(x=0; x<10; x++)
//the first element is stored in 0 while the last element in the array is NULL
cout<<number[x]<<endl;This would display:
1
2
3
4
5
6
7
8
9
10
To input into the array you can use the previous loop or individually:for(x=0; x<10; x++)
cin>>numbers[x];
//this will have you input until the array is full
#include <iostream.h>
#include <conio.h>
main()
{
int quantity[10], x; //declare numbers[10] as an array and x as a counter
for(x=0; x<10; x++)
do
{
cout << ("\nPlease enter the quantity sold ");
cin >> quantity[x];
if (quantity < 1 || quantity > 10)
{
cout << ("\nINVALID QUANTITY. TRY A NUMBER FROM 1-10 \n");
}
}
while (quantity < 1 || quantity > 10);
getch();
}
what am i doing wrong here ?
Dinglish 0 Newbie Poster
i'm sorry if i come across dumb, but how would i put your example code into a program like mine ?
i am confused.
#include <iostream.h>
#include <conio.h>
main()
{
int quantity[size];
const int size=10;
do
{
cout << ("\nPlease enter the quantity sold ");
for (int i=0; i < size; i++)
{
cout<<"Enter value - " << i << "- : " ;
cin >> quantity[i]; //Assigning from input to array.
}
if (quantity < 1 || quantity > 10)
{
cout << ("\nINVALID QUANTITY. TRY A NUMBER FROM 1-10 \n");
for (int i=0; i < size; i++)
{
cout<<"Enter value - " << i << "- : " ;
cin >> quantity[i]; //Assigning from input to array.
}
}
}
while (quantity < 1 || quantity > 10);
getch();
}
i tried this
Dinglish 0 Newbie Poster
I understand the concept of arrays. As well as yourselves, the text book explained this to me, but applying it to my program is not explained.
how would i assign the values i input, into an array? if someone could show me an example for this piece of code, i might be able to do the rest myself....
#include <iostream.h>
#include <conio.h>
main()
{
int quantity;
do
{
cout << ("\nPlease enter the quantity sold ");
cin >> quantity;
if (quantity < 1 || quantity > 10)
{
cout << ("\nINVALID QUANTITY. TRY A NUMBER FROM 1-10 \n");
}
}
while (quantity < 1 || quantity > 10);
getch();
}
for example for 5 different values entered
Dinglish 0 Newbie Poster
i am writing a program whereby i have written the instructions the shell of the program, and have written code for inputting values, but how do i collect all the information i have inputted. I am aware it involves arrays but can you help and point me in the right direction ?
Here is part of my program:
#include <iostream.h>
#include <string>
#include <conio.h>
main()
{
int salescode, bikeprice, modelcode, quantity;
string date;
char answer; //either yes or no
do
//the instructions to enter the i.d. code will be repeated (do...while
//loop) as long as the salescode is less than 1 or greater than 20.
{
cout << "\n\nPlease enter your identifiction code ";
cin >> salescode;
//the condition is tested
if (salescode < 1 || salescode > 20)
{
cout << ("\nTHIS I.D. CODE IS NOT VALID. TRY AGAIN \n");
}
}
//the instructions to enter the i.d. code will be repeated (do...while
//loop) as long as the salescode is less than 1 or greater than 20.
while (1 > salescode || salescode > 20);
//another do...while loop
do
{
cout << "\nPlease enter the bike price (one unit = 1 Euro) ";
cin >> bikeprice;
if (bikeprice < 1 || bikeprice > 500)
{
cout << ("\nINVALID PRICE. Bike prices cannot be 0 or more than 500. TRY AGAIN \n");
}
}
while (bikeprice < 1 || bikeprice > 500);
//another do...while loop
do
{
cout << "\nPlease enter the 3 digit model code ";
cin …
Dinglish 0 Newbie Poster
Your while statement is on the wrong line. It should be at the close of your do loop, but it's currently at the close of your switch.
thank you for your help
Dinglish 0 Newbie Poster
A do while combined with a switch sounds correct. What is your while condition? It should probably be something like:
char c;
do{
...switch...
}
while (c!='y');(but adding an OR (||) to the while to account for an entry of "yes")
oh, and just so you know, for loops are typically used when you want to carry out an operation a specified number of times. Here, as you can probably see, that is not the case as it could be as many times as the user doesn't input 'y'.
#include <iostream.h>
#include <string>
#include <conio.h>
main()
{
string date;
char answer; //either yes or no
bool check;
do { //beginning of loop********************************
cout << "\nplease enter the date in dd/mm/yyyy: ";
cin >> date;
cout << "\nIs this the correct date ? press y/n \n" << date << "\n\n";
cin >> answer;
switch (answer) {
case 'y':
cout << "\nThank you!!\n";
break;
}while (answer != 'y');
}
}
why does this not compile ?
btw, i am using borland 5.03 and HAVE to use it.
Info :Compiling E:\program\noname00.cpp
Warn : string.h(549,3):Functions containing for are not expanded inline
Warn : string.h(557,3):Functions containing while are not expanded inline
Warn : string.h(563,3):Functions containing for are not expanded inline
Warn : string.h(575,3):Functions containing for are not expanded inline
Warn : string.cc(686,32):Comparing signed and unsigned values
Warn : string.cc(658,22):Cannot create pre-compiled header: code in header
Warn …
Dinglish 0 Newbie Poster
I have a c++ problem regarding looping. I am writing a program which will include a problem similar to below.
1) ok, i am writing a program that asks the user to enter a number.
2) Then ask the user if the number entered was correct.
3) If the number is correct, the user will enter 'y' or 'yes' and the program will terminate.
(pretty simple so far ?
4) If the user enters 'n' or 'no' the program should loop back to the beginning of the program and start again. goes back to 1)
5) However, if the user enters anything other than 'yes' or 'no', the program rejects this input and tells the user to re-enter, using only 'yes' or 'no'.
6) This should be asked infinitely until either 'yes' or 'no' is inputted, after which the program then loops back to the beginning.
how would i do this ?
i've been trying do while and switch but no luck. would i have to use a for loop ?
Thanks
Dinglish 0 Newbie Poster
ok, what i posted before was a little too difficult for a begginer like me.
I tried to a different way,
Here is my ORIGINAL UNCOMPLETE PROGRAM I AM ASSEMBLING SO FAR:
#include <iostream.h>
#include <conio.h>
void WeeklySales(); //we make weeklysales a function here too
main()
{
int number;
do
{ //displays the menu
cout << "******Sales System******";
cout << ("\n\n");
cout << "1. Display Company Logo.\n"; endl;
cout << "2. Input/Validate weekly sales data.\n";endl;
cout << "3. Calculate weekly sales.\n";endl;
cout << "4. Display reciept.\n";endl;
cout << "5. SHUT DOWN & LOG OFF.\n";endl;
cout << "\nEnter number...\n";endl;
cin >> number;
cout << ("\n\n");
switch (number) //<--the expression is a variable (number) & controls the switch
//the value of (number) is tested against a list of constants.
//When a match is found, the statement sequence assosciated with that match is executed
{
case 1: //<----- const = 1
cout << ("\n\tUU\tUU \tEEEEEEEE \tLL\t\t \SSSSSSS\n\tUU\tUU \tEE \t\tLL\t\tS\n\tUU\tUU \tEE \t\tLL\t\tS\n\tUU\tUU \tEEEEEEE \t\LL\t\t\ SSSSSS\n\tUU\tUU \tEE \t\tLL\t\t S\n\tUU\tUU \tEE \t \t\LL \t\t S \n\t UUUUUUUU *\tEEEEEEEE *\tLLLLLLL *\tSSSSSSS *\n\n\n\n\n");break;
case 2: //<------const = 2. if match found, executes, then calls the weeklysales function below
cout << ("Weekly sales data\n\----------------- ");
WeeklySales(); //<------------- function call here
break;
case 3:
cout << ("Calculate weekly sales "); break;
case 4:
cout << ("Display receipt "); break;
case 5:
cout << ("Goodbye, and thank you for using U.E.L.S. ");break;
//default statement sequence is executed if no matches are found
default:
cout << ("Enter a number …
Dinglish 0 Newbie Poster
i'm sorry, is this better ?
#include <iostream.h>
#include <conio.h>
int main()
{
int day,dd,mm,yy,num;
char ans;
clrscr();
do{
cout<<"Enter Month: \n";
cin> > mm;
}while (mm<1||mm>12);
do{
cout<<"Enter Day: \n";
cin>> dd;
}while (dd<1||dd>31);
do{
cout<<"Enter Year: \n";
cin>> yy;
}while (yy<1||yy==num);
// validation
switch (mm){
case 1: if (1,3,5,7,8,10,12);
day=31;
break;
case 2: if (4,6,9,11);
day=30;
break;
case 3 :
if(((yy%4==0)&&(yy%100!=0))||(yy%400==0))
day=29;
else
day=28;
}
if (dd, mm, yy)
cout<<"The Date "<<mm<<'/'<<dd<<'/'<<yy<<" is VALID!"<<endl;
else
cout<< "The Date "<<mm<<'/'<<dd<<'/'<<yy<<" is INVALID!"<<endl;
do{
cout<<"do you want to try again?? (Y/N) "<<endl;
cin>>ans;
} while (ans!='n'&&ans!='N');
getch();
}
i
Dinglish 0 Newbie Poster
I began teaching myself programming 3 weeks ago. Its hard (for me) i'm trying to include some date validating within a program i am writing.
this is what i have so far, but invalid dates are validated unfortunately.
eg. November 31 2010
or february 30 2012
have a look and help me out please
#include <iostream.h>
#include <conio.h>
int main()
{
int day,dd,mm,yy,num;
char ans;
clrscr();
do{
cout<<"Enter Month: \n";
cin>> mm;
}while (mm<1||mm>12);
do{
cout<<"Enter Day: \n";
cin>> dd;
}while (dd<1||dd>31);
do{
cout<<"Enter Year: \n";
cin>> yy;
}while (yy<1||yy==num);
// validation
switch (mm){
case 1: if (1,3,5,7,8,10,12);
day=31;
break;
case 2: if (4,6,9,11);
day=30;
break;
case 3 :
if(((yy%4==0)&&(yy%100!=0))||(yy%400==0))
day=29;
else
day=28;
}
if (dd, mm, yy)
cout<<"The Date "<<mm<<'/'<<dd<<'/'<<yy<<" is VALID!"<<endl;
else
cout<< "The Date "<<mm<<'/'<<dd<<'/'<<yy<<" is INVALID!"<<endl;
do{
cout<<"do you want to try again?? (Y/N) "<<endl;
cin>>ans;
} while (ans!='n'&&ans!='N');
getch();
}
Dinglish 0 Newbie Poster
part 1 was to display a suitable text-based logo for the company.
part 2 was to input data from the keyboard:
salesman code (integer 1-20)
bike price
model code
quantity sold
date
Validate each data item; if an error is detected display an appropriate message and allow the user to re-type the data
I think i did the first part is ok, but i have no idea how to validate the date.
#include <iostream.h>
#include <conio.h>
main()
{
int number;
cout << "******Sales System******";
do
{
cout << ("\n\n");
cout << "1. Display Company Logo.\n"; endl;
cout << "2. Input/Validate weekly sales data.\n";endl;
cout << "3. Calculate weekly sales.\n";endl;
cout << "4. Display reciept.\n";endl;
cout << "5. SHUT DOWN & LOG OFF.\n";endl;
cout << "\nEnter number...\n";endl;
cin >> number;
cout << ("\n");
switch (number)
{
case 1:
cout << ("\n\tUU\tUU \tEEEEEEEE \tLL\t\t \SSSSSSS\n\tUU\tUU \tEE \t\tLL\t\tS\n\tUU\tUU \tEE \t\tLL\t\tS\n\tUU\tUU \tEEEEEEE \t\LL\t\t\ SSSSSS\n\tUU\tUU \tEE \t\tLL\t\t S\n\tUU\tUU \tEE \t \t\LL \t\t S \n\t UUUUUUUU *\tEEEEEEEE *\tLLLLLLL *\tSSSSSSS *\n\n\n\n\n");break;
case 2:
cout << ("Input/validate weekly sales data"); break;
case 3:
cout << ("Calculate weekly sales "); break;
case 4:
cout << ("Display receipt "); break;
case 5:
cout << ("Goodbye, and thank you for using U.E.L.S. ");break;
default:
cout << ("Enter a number from 1-5 only!");
}
} while (number !=5);
getch();
}
how would i incorporate the second part of the program in to the first (within case 2) and run it successfully ?
…
Dinglish 0 Newbie Poster
I am new to programming and i am teaching myself. (my teachers are not very good)
I am attempting an old assignment that a colleage had completed in school.
He told me it was pretty basic in terms of c++ programming.
UELS is a company selling bicycles;
Customers may opt to buy more than one bicycle as long as it is the same model.
If other models are also required then a separate transaction must be made.
The sales process is decided to be automated.
I have to implement and test a sales program.
The first task is to produce a menu (see below):
1. display company logo
2. input/validate weekly sales data
3. calculate weekly sales
4. display reciept
5. exit
I am attempting the options part by part.
i attempted the first part, but it didn't compile
CAN anyone help ?
I'd be extremely appreciative of any hints and help
(my code)
#include <iostream.h>
main()
{
int number;
cout << "1. Display Company Logo.";
cout << "2. Input/Validate weekly sales data.";
cout << "3. Calculate weekly sales.";
cout << "4. Display reciept.";
cout << "5. Exit.";
cout << "\nEnter number...\n";
cin >> number;
switch (number)
{
case [1]:cout << "\n\tUU\tUU \tEEEEEEEE \tLL\t\t \SSSSSSS";
"\n\tUU\tUU \tEE \t\tLL\t\tS";
"\n\tUU\tUU \tEE \t\tLL\t\tS";
"\n\tUU\tUU \tEEEEEEE \t\LL\t\t\ SSSSSS";
"\n\tUU\tUU \tEE \t\t\LL\t\t S";
"\n\tUU\tUU \tEE \t \t\LL \t\t S ";
"\n\t UUUUUUUU *\tEEEEEEEE …
Dinglish 0 Newbie Poster
Hi, i'm Adamand i'm new to programming.
From the u.k. studying c++.
I need a lot of advice and help.