Hello and Help

This is a discussion on Hello and Help within the C++ Programming forums, part of the General Programming Boards category; You can test it yourself by downloading Dev C++. you don't have to be in your lab. Code: transform(answer.begin(), answer.end(), ...

  1. #16
    System.out.println("");
    Join Date
    Jan 2005
    Posts
    84
    You can test it yourself by downloading Dev C++. you don't have to be in your lab.

    Code:
    transform(answer.begin(), answer.end(), answer.begin(), ::tolower);
    Converts the string from uppcase to lowercase. That way when you compare names JOHNSON=johnson = JoHnSoN. Otherwise they won't match.

    Code:
    std::cin.ignore();
    std::cin.get()
    When you run your programs some places make your window appear and then close right away (if you aren't in a DOS window or terminal). This will leave it open until you press enter.

  2. #17
    Registered User [Z-D]'s Avatar
    Join Date
    Oct 2006
    Posts
    37
    Quote Originally Posted by robatino
    Code:
    std::numeric_limits<std::streamsize>::max(here) is equal to the maximum value of a variable of type std::streamsize.
    Quote Originally Posted by Loctan
    You can test it yourself by downloading Dev C++. you don't have to be in your lab.

    Code:
    transform(answer.begin(here), answer.end(here), answer.begin(here), ::tolower);
    Converts the string from uppcase to lowercase. That way when you compare names JOHNSON=johnson = JoHnSoN. Otherwise they won't match.

    Code:
    std::cin.ignore(here);
    std::cin.get(here)
    When you run your programs some places make your window appear and then close right away (if you aren't in a DOS window or terminal). This will leave it open until you press enter.
    Okay, I'll look into Dev C++...
    Thanks for explaining... So i'm suppose to write the values here right? Or not?....

    But, do I need them in my programming?... And do you think it will work?....


    Okay, so here's another question in my assignment.

    Write a programme that can read the type of fruits, quantity, unit price and the total price.
    Here's my programme:
    Either this...
    Code:
    #include <iostream>
    #include <string>
    
    main ()
    
    {
    	int quantity, total
    	std::string s;
    	std::cout << "Fruits available: Apple, Banana and Orange";
    	std::cout << "Enter type of fruits: ";
    	std::cin >> s;
    	std::cout << "Enter quantity: ";
    	std::cin >> quantity;
    
    	if (s == "Apple")
    	{
    		std::cout << "Unit per price: $10";
    		total = quantity * 10;
    		std::cout << "Your total amount: $" << total;
    	}
    
    	if (s == "Banana")
    	{
    		std::cout << "Unit per price: $8";
    		total = quantity * 8;
    		std::cout << "Your total amount: $" << total;
    	}
    
    	if (s == "Orange")
    	{
    		std::cout << "Unit per price: $15";
    		total = quantity * 15;
    		std::cout << "Your total amount: $" << total;
    	}
    
    	else
    	{
    		std::cout << "Fruit entered not available";
    	}
    
    	return 0:
    }
    or this....
    Code:
    #include <iostream>
    #include <string>
    
    main ()
    
    {
    	int quantity, price, total
    	std::string s;
    	std::cout << "Fruits available: Apple, Banana and Orange";
    	std::cout << "Enter type of fruits: ";
    	std::cin >> s;
    	std::cout << "Enter quantity: ";
    	std::cin >> quantity;
    
    	if (s == "Apple");
    	{
    		price = 10;
    	}
    
    	if (s == "Banana")
    	{
    		price = 8;
    	}
    
    	if (s == "Orange")
    	{
    		price = 15;
    	}
    
    	std::cout << "Unit per price: $" << price; 
    	total = price * quantity;
    	std::cout << "Your total amount: $" << total;
    
    	else
    	{
    		std::cout << "Fruit entered not available";
    	}
    
    	return 0:
    }
    Would they work? I'm not so cerain about how I used the else on both programmes. And Im less confident for the second programme compared to the first. Again I haven't tested these because.... bla blab bla....
    Which one is better?

    Also, is it necessary to use endl;? When trying it, it work on <iostream.h> but not <iostream>. Did I get that right? And when do I know which one to use?...
    EDIT: Ohhh. I just remembered that for <iostream> we use std::endl; instead of just endl;. So no need to answere that question. But I'm still unsure when it is appropriate to use it.

    Regarding this
    Code:
    main ()
    and
    Code:
    int main ()
    What's the difference between them? Why is int sometimes used before main?

    Lastly I'm I asking too many questions. Please tell me if I am. I don't want to be a nuisance to you guys.
    Last edited by [Z-D]; 10-20-2006 at 10:41 AM.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21