Help with first programming asignment

1
Last edited on
When you get a bunch of errors, always start with the first one first. Fix the error, compile the code, and if there are still errors, again fix the first error first, ... and eventually you should have no compiler errors left.

The first error here has to do with a missing semicolon on line 9.
Nice try BBGUN

First, the name of the product is a string, so the data type for that variable should be string .

Also, setting all the price types as int truncates the fractional part of the results after the computation of profitPercentage .

Declare them as double or float .

In line 9, you left out a semicolon after the declaration of profitPercentage .

After having declared productName as string ,

use the comands:
1
2
3
4
5
 
    cin>>productName;    //must include <string> library. 
                                     //stop input after space. You can experiment.
    getline(cin,productName);    // <string> library. 
                                             //stop input at new line (enter) 


With all these done, your code should be fixed.
1
Last edited on
I cant say if everything looks good or not.
If the program works the way you want Fine. It then looks good. Else, polish it to your taste.
We will be here to help you accomplish that.
1
Last edited on
simply add a cout<<endl; where you want an empty space or put a '\n' before each instruction.

like this cout<<"\nEnter the cost of the product:\n"; .

Your program does not work properly if i enter Ball pen as the product well.
Fix that...
Do you have any tips? It works if the product name is just one word.
One way to fix it is to ask them to not have any space and to do underscore 'ball_pen'


1
2
3
4

cout<<"Please do not enter any spaces instead use underscore in the product's name =D<<endl;
cout << "Enter the name of the product:\n";
cin >> productName; 
Use getline(cin,productName) instead of cin>>productName.This will take the whole length of the string including spaces.
Topic archived. No new replies allowed.