Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
Sign in to follow this  
Blackbound

Lesson 1: Think boy think

Recommended Posts

for this lesson, we will be using variables and introduce a new function.

 

 

#include <iostream>
using namespace std;

int main(){
int food;
int quantity;
float price;

cout << "What do you want for dinner?" << endl << "1: Pizza \n 2: Pasta \n 3: Pocky \n I want ";
cin >> food;
if (food == 1)
{
cout << "how much Pizza do you want?" << endl;

	cin >> quantity;
	cout << "PREPARE THE OVENS WE HAVE " << quantity << " PIZZAS ON THE WAY!" << endl;
price = 3.95 * quantity;
	cout << "here is your food, your payment is " << price << endl;
} else if (food == 2)
{
cout << "how many pasta bowls do you want?" << endl;
	cin >> quantity;
	cout << "PREPARE THE BOILERS WE HAVE " << quantity << " PASTA BOWLS ON THE WAY!" << endl;
price = 8.95 * quantity;
	cout << "here is your food, your payment is " << price << endl;

} else if (food == 3)
{
cout << "how many boxes of pocky do you want?" << endl;
	cin >> quantity;
	cout << "PREPARE THE SHOPSEARCHERS WE HAVE " << quantity << " BOXES OF POCKY TO FIND!" << endl;
price = 1.95 * quantity;
	cout << "here is your food, your payment is " << price << endl;
} else
{
cout << "sorry we dont have any other items";
}
system("pause");
}

 

As you can see we have some new stuff in this code.

 

int food;

This creates our first variable called an int (which is basically a whole number above or below 0)

 

 

float price;

This creates another variable named price. This time its a float. The differences between a float and an int is that a float takes more memory space and an int is less accurate. (you cant do real prices with the int variable)

 

if (condition)

This checks and performs the next command if the command or the next series of commands if the condition is true. This is usually followed up by the keyword "else" or "else if(condition)," there is no semicolon on the end if statements. If you want to use a single command after the if statement, don't use brackets.

 

cin >> (Variable name);

This tells the compiler to ask the user for input for the variable used.

Share this post


Link to post
Share on other sites

HOMEWORK

 

create a function that takes a user input and sets it to 3 possible outputs

Share this post


Link to post
Share on other sites

BlackBound; I put the code in exactly as you have it and it said "0 successful, 1 failed".

Share this post


Link to post
Share on other sites

did you also see that there was a scrollbar in the codebox?

did you get every line of code in the codebox?

Share this post


Link to post
Share on other sites

what does the error say? if it gives a line number whats the line number?

Share this post


Link to post
Share on other sites

Ok. This is what I have in the file:

 

#include <iostream>
using namespace std;
int main(){
int food;
int quantity;
float price;
cout << "What do you want for dinner?" << endl << "1: Pizza \n 2: Pasta \n 3: Pocky \n I want ";
cin >> food;
if (food == 1)
{
cout << "How much Pizza do you want?" << endl;
	cin >> quantity;
	cout << "PREPARE THE OVENS WE HAVE " << quantity << " PIZZAS ON THE WAY!" << endl;
price = 3.95 * quantity;
	cout << "here is your food, your payment is " << price << endl;
} else if (food == 2)
{
cout << "how many pasta bowls do you want?"  << endl;
cin >> quantity;
cout << "PREPARE THE BOILERS WE HAVE " << quantity << " PASTA BOWLS ON THE WAY!" << endl;
price = 8.95 * quantity;
cout << "here is your food, your payment is " << price << endl;
} else if (food == 3)
{
cout << "how many boxes of pocky do you want?" << endl;
cin >> quantity;
cout << "PREPARE THE SHOPSEARCHERS WE HAVE " << quantity << " BOXES OF POCKY TO FIND!" << endl;
price = 1.95 * quantity;
cout << "here is your food, your payment is " << price << endl;
} else
{
cout << "sorry we dont have any other items";
}
system("pause");
{

 

And the error that pops up is this:

 

------ Build started: Project: 2ndProject, Configuration: Debug Win32 ------

Compiling...

Main.cpp

.\Main.cpp(14) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data

.\Main.cpp(21) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data

.\Main.cpp(28) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data

.\Main.cpp(36) : fatal error C1075: end of file found before the left brace '{' at '.\Main.cpp(35)' was matched

Build log was saved at "file://c:\Documents and Settings\Owner\My Documents\Visual Studio 2008\Projects\2ndProject\2ndProject\Debug\BuildLog.htm"

2ndProject - 1 error(s), 3 warning(s)

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Share this post


Link to post
Share on other sites

flip the brace at the end of the file

 

the last one is {, it should be }

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...