Question:
Having problems compiling my code for C++?
anonymous
2012-02-10 21:59:11 UTC
Consider the following program segment:
//include statement(s)
//using namespace statement
int main ()
{
//variable declaration
//executable statements
//return statement
}
a. Write C++ statements that include the header files iostream and string.
b. Write a C++ statement that allows you to use cout, and endl without the prefix std::.
c. Write C++ statements that declare the following variables: name of type string and studyhours of type double.
d. Write C++ statements that prompt and input a string into name and a double value into studyhours.
e. Write a C++ statement that outputs the values of name and studyHours with the appropriate text. For example, if the value of name is “Donald” and the value of studyHours is 4.5, the output is:
Hello, Donald! On Saturday, you need to study 4.5 hours for the exam.
f. Compile and run your program.
_________________________________________________
The Code I have so far:

#include
#include

using namespace std;

int main() {

sting name;
double studyHours;


name = "Donald Smith";
studyHours = "4.5";

cout<<"Hello,"<< name << "! On Saturday you will need to study"<< studyHours << "for the exam."<< endl;

cin.get();
return();



}

_______________________________________
it is showing that there a problem where it say sting name
Four answers:
green meklar
2012-02-10 22:13:29 UTC
Okay, the first mistake is here:



sting name;



I think the variable type you wanted is 'string'. Right now you have 'sting'. Put in the extra R and it will work better.



That said, there is another error here:



studyHours = "4.5";



The "4.5" is a string literal, but studyHours is of type double. I recommend removing the quote marks, otherwise you will get a compile error.



Finally, this may also give a compile error:



return();



I'm not sure that an empty set of brackets is a legal integer expression in C++. My guess is, probably not.
Lisa A
2012-02-10 22:01:33 UTC
Wow. I am flabbergasted. Someone actually took the time to read the error message that was output by the compiler. That is rare.



But what I am actually flabbergasted about is how you could fail to comprehend the error message.



Think about it! What exactly is a sting??
Ratchetr
2012-02-10 22:09:38 UTC
You got stung by a sting.



You should try using a string instead.
jackett
2016-11-07 07:21:53 UTC
<< is undefined for integers. you want to rework num1 to a string. also , your universal should be a glide yet that isn't your mistakes (till you attempt to print it at which period it desires to be switched over to thread also. Personalty i exploit sprintf for my conversions char textual content[5]; sprintf(textual content,%d,num1);


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...