computer engW 0 Light Poster

Thank you for all your replies....

computer engW 0 Light Poster

Could any one answer my questions??

computer engW 0 Light Poster

Thanks so much.

computer engW 0 Light Poster

Here i have problem with ctype.h library .I think i use correctly,but i ahve an error on it.
This is the code.

#include<iostream>
#include <ctype.h>
using namespace std;
int main(){
	char letter;
	int num;
	int isdigit(int letter);
	int  isupper (int letter);
	int islower( int letter);
	int small=0;
	int capital=0;
	int number=0;
	int special=0;

	 cout<<"Enter any number and letter you like,'+'means   exit";
	 /* use if statement to help user to count how many times s/he enter letter*/
   for(int i=0;i<=5;i++)  //any number greater than one
	{     //start while here
	

	  cin>>letter; //user enter a number
	  if (letter==isdigit(letter))
		  number++;
	  if(letter==isupper(letter))
		capital++;  //counting capital letter
	  else  if(letter==islower(letter))
		  small++;  //in case enter small, letter counting small letter
	  
	  else if(letter!=isupper(letter) && letter!=islower(letter) && num!=isdigit(num))
		  special++;  /*if the user enter a sepcial                                    chraecter*/

   }
	  
	
	

      cout<<number<<endl<<small<<endl<<capital<<endl<<special;
return 0;
}
computer engW 0 Light Poster

You can also see this URL http://www.daniweb.com/forums/thread67837.html

thekashyap wrote some problems(1,2,3) they related to graohs .

computer engW 0 Light Poster

Right, well, I'm not sure I understand what you are asking...

Which shapes do you need to learn how to draw? Just a square/triangle? That would be where I would start...

So what do you mean by math calculations?

Please look to this code

#include <iostream>
using namespace std; // So the program can see cout and endl

int main()
{
int n = 4;
int line, stars, loop;
for (line = 1; line <= n; line++)
{
                   stars = n - line + 1;
    for (loop = 1; loop <= stars; loop++)
        cout << "*";
    cout << endl;
}
}

they use a simple math colculation stars = n - line + 1; in order to output the shape.However, i think there are a relationship between some shapes -correct me if iam wrong-
Which shapes i'd like to learn like differnt shapes of triangle ,sequsre, rectangle ,but i guess that triangle shapes will be come on the exam ^_^

computer engW 0 Light Poster

Thank you so much,but i have problem with another prgram i will post it here.

Thanks again

computer engW 0 Light Poster

Or else you do a few math calculations, then set up a function to draw individual shapes....

For example, you could create a "square" function:

void draw_square(int sideLength);

which basically loops and outputs a square (of the specified size, using a loop) to the screen...

Advantage: you can create reusable shape-builders...to make more shapes...haha

EDIT: niek_e is right, what specifically do you need help with, rather than us just posting code...

Could you tell me how can i use Math caculations to write these kind iof codes.
Becus sometime i found in other wbsites they use Math calculations.

computer engW 0 Light Poster

There's isn't a magic code to draw 'all shapes'
I guess this is a homework assignment to learn loops?
If yes: Post your attempt here (are tell us what part you don't understand), and you'll get help.
if no: The easiest way to draw the shape in your post is: std::cout << "*****\n****\n***\n**\n*";

Our doctor want us learn how to make these shapes by using loops for exam question.She gave us a question ,we should use loop when solving it.

#include <iostream>
using namespace std; // So the program can see cout and endl

int main()
{
int n = 4;
int line, stars, loop;
for (line = 1; line <= n; line++)
{
                   stars = n - line + 1;
    for (loop = 1; loop <= stars; loop++)
        cout << "*";
    cout << endl;
}

}
The shape will be the same as what i draw.

computer engW 0 Light Poster

Hi,
When i write any code has if else statement , and run it na error appeatrs and say that else doesn't match with if or illegal else without matching if.
I don't know where is the problem exctly ,and you should know that i don't put } in these program.
For example this program-

#include<iostream>
using namespace std;
int main(){  
	int year ,month,day,leapyear;
	cout<<"Enter a year and month ";
	cin>>month>>year;
	if ((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0))){
		leapyear=1;
	   cout<<"This is aleap year";
	   else{
	   cout<<"This is not leap year";
	   }
	}
return 0;
}
computer engW 0 Light Poster

Hi everyone,

Today i have a question about how can i write one code for all shapes like, ******
*****
****
***
**
*

or other shapes like square or tringle.

I want to know the difference in every code.
Thanks alot.

computer engW 0 Light Poster

I try to solve this question in two ways,but it didn't work as i want .
1'st way

#include<iostream>
using namespace std;
int main(){
    int value,newvalue;
    cout<<"Enter a number ,and -1 means exit:  ";
    cin>>value;
    do
    {
    cout<<"Enter a new value : ";
    int newvalue;
    cin>>newvalue;
    if(newvalue>value)
    {
      cout<<value;
    }//end of if
    else{
      cout<<"  ";
    }//end of else
    value=newvalue;


    }//end of do
    while(value!=-1);

return 0;

}

I always ask the user to enter new value and that not what i want .

2'nd way:

#include<iostream>
using namespace std;
int main(){
    int value,newvalue;
    cout<<"Enter a number ,and -1 means exit:  ";
    cin>>value;
    cout<<"Enter a new value : ";
    cin>>newvalue;
    while(value!=-1);
    {

    if(newvalue>value)
    {
      cout<<value;
    } //end of if
    else{
      cout<<"  ";
    } //end of else
    value=newvalue;


    } //end of do


return 0;

}

It asks user to enter a value and new value once ,after that it stopped.
One thing i can't understand it and is why the program do not do (value=newvalue)?in both program.

computer engW 0 Light Poster

Now that your code is in the shape in which it compiles properly, you can start testing your programs to see if they work as expected.

Thanks alot i will run it and if i have any problem i will tell you ,otherwise i will mark this Thread as solved.

Thanks again

computer engW 0 Light Poster

Thanks alot.
I will be more careful about braces {}.

Do i have another mistakes??

computer engW 0 Light Poster

Hi mitrmkar ;
I am afriad i don't know what do you mean by (icode/icode).?
However,
I have another 2 questions and there solutions,please if anyone see any mistakes tell me.
Q4 : Starting with the first value of a list (ending with -1) print only the sub-list of values in increasing order.
Example:
Input: 1 4 2 7 3 9 6 -1
Output: 1 4 7 9
Solution:

#include<iostream>
using namespace std;
int main(){
	int value,newvalue;
	cout<<"Enter 2 numbers ,and -1 means exit:  ";
	cin>>value>>newvalue;
	do
	{
	if(newvalue>value)
	  cout<<value;
	else
	  cout<<"  ";
	value=newvalue;
	
	 
	}
	while(value!=-1);

return 0;

}

After i write newvalue the compiler run with out any result,only blank screen.

Q 5:Write a program that accepts a positive integer and gives its prime factorization; that is expresses the integer as a product of primes or indicates that it is a prime.
Solution:

#include<iostream>
using namespace std;
int main(){

	cout<<"Enter any number: ";
	int n;
	cin>>n;
	int i=2;
	while(i<=n)
	{
	if(n%i==0)
	  cout<<i<<"*";
	  n=n/i;
	else  i++;
	 }
	cout<<n;
return 0;
}

In this program i have an error is( expected ';'before "else") ,but i can't understand this error because it is clear that i put semi colon.


Thanks alot.

computer engW 0 Light Poster

Could any one help me????

computer engW 0 Light Poster

I did small changes in Q1,

#include<iostream>
using namespace std;
int main(){
	int value,check=1;
	cout<<"Enter a number:  ";
	cin>>value;
	while(value>=0)
	{
	int newvalue;
	cout<<"Enter another value:  ";
	cin>>newvalue;
	if(value>newvalue)
	  cout<<" is increasing";
	  check=0;
	  value=-5;
	else
	value=nwvalue;
	if(check==1)
	value==-5
	  cout<<" this is  not increasing order";
        else
	cout<<"This is increasing order";
	}

return 0;
}
computer engW 0 Light Poster

Today I have some question and their solution ,but I have problem with some.


Q1: Write a program that checks if a sequence of positive numbers is in increasing order or not.
I don't know what is missing her?!

Solution:

#include<iostream>
using namespace std;
int main(){
	int value,check=1;
	cout<<"Enter a number:  ";
	cin>>value;
	while(value>=0)
	{
	int newvalue;
	cout<<"Enter another value:  ";
	cin>>newvalue;
	if(value>newvalue)
	  cout<<" ....Not sequence";
	  value=-1;
	else
	value=nwvalue;
	if(check==1)
	  cout<<"....is increasing";
	}

return 0;
}

Q 2: Let f(x,n) = x –x3/3! + x5/5! - …+(-1)n x2n+1 /(2n+1)!
Using a loop write a program to calculate f(x,n).

Solution:

#include<iostream>
#include<cmath>
using namespace std;
int main(){
	cout<<"Enter a number ";
	int m;
	cin>>m;
	for(double x=1;x<=m;x++)
	{
	  for(double n=1;n<=x;n++)
	  {
	  n=2*n+1;
	  double fact=1; 
	  fact*=n;
	  double f=1;
	  f=pow(x,n)/fact;
	  cout<<f<<endl;
	  f*=-1;
	  } 
	double f;
	cout<< f<<endl;
	}
	


return 0;
}

Q3: Write a program that prints all possible combinations of 3 numbers between 1 and n.
After I run the compiler ,the output doesn't stop.
Solution:

#include<iostream>
using namespace std;
int main(){
	cout<<"Enter a number : ";
	int num;
	cin>>num;
	for(int i=1;i<=num-2;i++)
	{
	 cout<<i<<endl;
	
	  for(int j=1;j=num-1;j++)
	  {
	     
	     cout<<j<<endl;
	   
		for(int k=1;k<=num;k++)
	        {
		cout<<k<<endl;
		}
	   }
	 
	}

return 0;
}

Please tell me, What are my mistakes?

computer engW 0 Light Poster

Yes ,Of course i know factorial.I think i get your idea .Do you mean that i have to do nested for and one of the for statement calculate the factorial.

About ascii chart i don't have any idea .

computer engW 0 Light Poster

Hi Everyone ,
I have 3 questions that need explaination (only explain),then i will try to solve them.

Q1: Let g(x,n) = 1 – x2/2! + x4/4! - … …+(-1)n x2n /(2n)!
Using a loop write a program to calculate g(x,n).

Q2: write a program that accepts a positive integer and gives its prime factorization; that is expresses the integer as a product of primes or indicates that it is a prime.

Q3 is simple if i have numbers ,but in this case i have Character.
Write a program that reads three characters and prints the maximum and the minimum in alphabetical order.

Thanks for your time

computer engW 0 Light Poster

I know that it is not hard ,but it needs practice .
Thanks for your reply.

computer engW 0 Light Poster

Hi ;
I know how to solve the same problem if i have limit numbers ,but here i have n intergers .How can the compiler understanst me when i need n integers ,like this question:

Write a program that takes an n number of integers and calculates their average.
Using for or while loop!

computer engW 0 Light Poster

Thanks . Is that mean i had one mistake"quote"only.
Thanks again..

computer engW 0 Light Poster

Hi everone,
Today i have a question has two parts and i did what i undrstood.If threr are mistakes ,please tell me.

The Question is:

father decided to buy a new vehicle. He paid 20,000 QR in cash and the rest will be paid on settlements as follows:
 1500 QR per month for 12 months.
 800 QR per month for 24 months, and
 600 QR per month for 48 months.
Q1: Write a C++ program that asks the user to enter the number of months he wants and calculates the total price of the car.
Q2: Adjust the program so that it gives your father a discount on the total price of the car as follows:
 If the total price of the car is less than 38,500 QR the discount will be 15%.
 If the total price of the car is between 36,500 QR and 40,000 QR the discount will be 17%.

 If the total price of the car exceeds 40,000 QR the discount will be 17%.
The program should give now the total price of the car before and after the discount

My answer is :

#include <iostream>
#include<cmath>
using namespace std;
int main(){
	int month ;
	double price;
	cout<<"Enetre your month "; \\the month has to be 12,24 or 48  
	cin>>month ;
	if (month ==12)  
	   cout<<"Total price is= "<<(1500*12)+20000=";  \\total price for 12 months
	else if (month  ==24)
	   cout<<"Total price …
computer engW 0 Light Poster

Thanks for your help . Now it's work.
Thanks again

computer engW 0 Light Poster

Thanks alot BlackJavaBean .
I understood my errer in question two now.
About question one our doctor did not want to see if statement in the program,she wants us to use switch without if statement.

computer engW 0 Light Poster

I have some questions ,i can't solve it .The first one is,


Write a C++ program using the switch statement that does exactly what the following program does:

#include <iostream.h>
#include <math.h>
void main ()
{
   float number;
   int choice;
   cout<< "Enter you number";
   cin>> number;
   cout << "Enter your choice: 1=sin, 2=cos, 3=tan,       4=log ";
   cin >> choice;
   // nested if's:
   if (choice < 1  ||  choice > 4) {
      cout << "wrong choice";
   }
else{                           
      if (choice <= 2){                        
         if (choice == 1){
            cout << sin(number);
         }
         else{                     
            cout << cos(number);
         }
      }
else{                        
         if (choice == 3){
            cout << tan(number);
         }
         else{
            cout << log(number);
         }
      }
   }
}

Seconed question is:
-Write an interactive program that computes the area of a rectangle (area= base * height) or a triangle (area=0.5 * base * height) after prompting the user to type the first character of the figure name (R or T). Your program must display an error message to indicate that the user entered a character other than R or T.

My program look like this:

#include <iostream>
using namespace std;
int main()  {
  float base,heigh;
  char R,T;
  cin>>R ,T;
  cin>>base , heigh;
  if  (char== 'R')
     cout<<base * heigh<<"R" ;
  else  if (char=='T')
      cout<<0.5*base*heigh<<"T" ;
  else 
      cout<<"you enter neither R nor T";

 return 0;
}

After i compiled it i have these errors:

four.cpp:8: error: expected primary-expression before "char"
four.cpp:8: error: expected `)' before "char"

computer engW 0 Light Poster

Thanks for all the replies. I realy need help in c++ ,so i think i choice best place , that can help me .
Thank you a lot.

computer engW 0 Light Poster

I was looking for some websites ,that can help me in C++ becuase i have c++ course this semester .I really like your siteand I hope i can find help and greetingfrom the members.