college work

closed account (37S1hbRD)
I just stared my c++ class tonight. My first assessment is to write a C++ program that declares a value that can hold the price of a lunch. Prompt a user to enter the amount he or she spent on lunch. I got most of it done but i am having a few issues for exampled when i run it "How much money did you spend on lunch 6" and it says "You spent on lunch 6" I need it to say "You spent 6 on lunch" but i dont know how to get numbers to work in side of a cout.note i need it to work with any number not just one number thank you if you can help me.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Student.cpp : Defines the entry point for the console application.
// demomstrating a Student struct

#include "StdAfx.h"
#include<iostream>
using namespace std;
struct Lunch 
{
	int lunchmoney;
	
};


int main()
{
	Lunch oneSophomore;
cout << "How much money did you spend on lunch? ";
cin >> oneSophomore.lunchmoney;
cout << "You spent on lunch " <<
	oneSophomore.lunchmoney << endl;
    system("pause.exe");
	return 0;
}

You just need to break up the text like so:
 
std::cout << "*text* " << randomNumber << " *more text*" << std::endl;


Also, the Lunch struct isn't necessary (as a most structs with one public data member...), why not just declare a lunchmoney integer in main?
closed account (37S1hbRD)
ok i will do that thank you for your help.
closed account (37S1hbRD)
how do i stop << randomNumber << form showing up when i run it . note the number part of it if fixed
cout << "You spent << randomNumber << on lunch " <<
You are forgetting the quotation marks.

cout<<"You spent "<<oneSophmore.lunchmoney<<" on lunch."<<endl;
example:

1
2
3
4
5
6
7
8
9
10
11
#include "StdAfx.h"
#include<iostream>
using namespace std;

int main()
{
  int pie=5;
  //now I want to say that I have 5 pies.Notice my the space in the quotation marks.
  cout<<" I have "<<pie<<" pies"<<endl;
  return 0;
}
closed account (37S1hbRD)
thank you for your help it works know
Topic archived. No new replies allowed.